Monday, January 11, 2021

Prestashop 1.6.x - PHP 5.x to PHP 7.x Uncaught Error: Access to undeclared static property:

When upgrading PHP version for prestashop 1.6.x websites from 5.x to 7.x
some errors may occure (Prestashop guys confirm that max allowed version is 5.5)

Typical error is:

Uncaught Error: Access to undeclared static property: CLASS_NAME::PROPERTY/METHOD_NAME in ....
Example:
Uncaught Error: Access to undeclared static property: Validate::$data in ZZZ/classes/ObjectModel.php:1113
So i made change in 2 calsses (up to now) to make the website working :


in classes/controller/AdminController.php (Line 886 ???)
i've changed:
$return = $this->{'process'.Tools::toCamelCase($this->action)}();

to
$return = call_user_func_array(array($this, 'process'.Tools::toCamelCase($this->action)), array());


in classes/ObjectModel: (Line 1135 ???)
if (isset($data['validate']) && !Validate::$data['validate']($value) && (!empty($value) || $data['required']))

to
if (isset($data['validate']) && !call_user_func('Validate::'.$data['validate'],$value) && (!empty($value) || $data['required']))

Notice:
Even your website will reUp, it will be from time to other somme 500erros, in general they are in the same kind of the last indicated php instruction :
related to the call call_user_func that became mondatory