From 125bc3039f5e4d6cb490288e073a751c50e29f9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Hu=C4=8D=C3=ADk?= <petr@getdatakick.com> Date: Sat, 17 Dec 2022 14:35:08 +0100 Subject: [PATCH] Link::getAdminLink - check type of $params param Thirty bees 1.4.0 added new parameter $params to the method Link::getAdminLink() with default value. While this should be backwards compatible change, it still causes problems. Some module called Link::getAdminLink() with third paramter already. This parameter used to be ignored, but now it can cause type errors. This commit adds type check -- if the $params parameter is not array, we raise warning and initialize the parameter to empty array. In the future, this check will be replaced with an actual error message (by adding array to method signature) --- classes/Link.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/classes/Link.php b/classes/Link.php index f7f8a161f7..08fea3de66 100644 --- a/classes/Link.php +++ b/classes/Link.php @@ -318,6 +318,16 @@ public function getAdminLink($controller, $withToken = true, $params = []) { $idLang = Context::getContext()->language->id; + if (! is_array($params)) { + $callPoint = Tools::getCallPoint([Link::class]); + $errorMessage = 'Link::getAdminLink(): parameter $params has invalid type. '; + $errorMessage .= 'Expected array, got ' . gettype($params) . '. '; + $errorMessage .= 'This will raise error in future version of thirty bees. '; + $errorMessage .= 'Called from: ' . $callPoint['class'] . '::' . $callPoint['function'] . '() in ' . $callPoint['file'] . ':' . $callPoint['line']; + trigger_error($errorMessage, E_USER_WARNING); + $params = []; + } + if ($withToken) { $params['token'] = Tools::getAdminTokenLite($controller); }