_autoload to spl_autoload_register()

Magento 1.9.2.X on PHP 7 [SOLVED]

We host and manage a farm of servers with different virtual machines running different versions of PHP, flavours of linux and MYSQL databases. On one particular server which was running PHP5.5 or PHP 5.6 and we felt that it was time to upgrade to PHP 7.X  because some clients wanted an upgrade but we had one client running Magento 1.9.2.4 on it and we were worried that if we upgraded to PHP7 then all hell would break loose. We upgraded from PHP5.6 to PHP7.1; if you try to upgrade to PHP7.2 or 7.3 then things could be a bit more involved especially with the __autoload magic function.

The good news is it only took us about 30 minutes to fix everything and it wasn’t too difficult.

The main things to watch out for when upgrading from PHP5 to PHP7 are some syntax things within PHP – e.g.

(1) If a method expects 3 parameters and you only give 2 then in PHP7 it would return a fatal error whereas in PHP5 it would allow it and continue with the rest of the runtime script. So we found that some of our templates file had to be tweaked because our original developers were lazy and didn’t always enter the right number of parameters

e.g.

/app/code/core/Mage/Catalog/Helper/Output.php:120

productAttribute($product, $attributeHtml, $attributeName) is the method name and

In PHP5, the following will work but not in PHP7:-

$_helper->productAttribute($_product, $_product->getAttributeText(‘certifications’));

which we had to update to:-

$_helper->productAttribute($_product, $_product->getAttributeText(‘certifications’),’certifications’);

 To be honest, most developers should us the latter format anyways but the developers we got must have been lazy.

(2) We have identified the following files that need to be updated.

(i) app/code/core/Mage/Core/Model/Layout.php:555

within the method getOutput() { 
Change:-
$out .= $this->getBlock($callback[0])->$callback[1]();

to:-
$out .= $this->getBlock($callback[0])->{$callback[1]}();

(i) app/code/core/Mage/Core/Model/Layout.php

within the method getOutput() { 
Change:-
$out .= $this->getBlock($callback[0])->$callback[1]();

to:-
$out .= $this->getBlock($callback[0])->{$callback[1]}();

(ii) app/code/core/Mage/Core/functions.php:60 – On PHP 7.1 the following doesn’t need to change but for PHP7.2 or 7.3 the following does need to be updated. Before there is a magic function called __autoload() which has been deprecated in PHP7.2 and was replaced with spl_autoload_register()

_autoload to spl_autoload_register()
_autoload to spl_autoload_register()

The following is untested but try replacing __autoload() with spl_autoload_register() on line 60 of the functions.php file. We actually decided to use PHP7.1 instead of PHP 7.2 to avoid having to deal with this issue

(3) app/code/core/Mage/ImportExport/Model/Import/Uploader.php:135

Change:-
$params['object']->$params['method']($filePath);
to:-
$params['object']->{$params['method']}($filePath);

(4) app/code/core/Mage/ImportExport/Model/Export/Entity/Product/Type/Abstract.php:99

Change:-
$data['filter_options'] = $this->$data['options_method']();
to:-
$data['filter_options'] = $this->{$data['options_method']}();

(5) app/code/core/Mage/ImportExport/Model/Export/Entity/Customer.php:250

Change:-
$data['filter_options'] = $this->$data['options_method']();

to:-
$data['filter_options'] = $this->{$data['options_method']}();

(6) lib/Varien/File/Uploader.php:259

Change:-
$params['object']->$params['method']($this->_file['tmp_name']);
to:-
$params['object']->{$params['method']}($this->_file['tmp_name']);

(7) app/code/core/Mage/Core/Model/Resource/Session.php:218

Change:-
return $data;
to:-
return (string)$data;
PHP7 has a stricter variable type casting standard and you must specify the return of a string.

The other potential issue that the grand_total calculation could be off and that requires a tweak in config.xml – this did not affect us but I read online that some people experience this issue. Please check http://scriptbaker.com/tag/magento-1-9/ <= This link seems to have died for some reason.

(8) /app/code/core/Mage/Sales/etc/config.xml:1212 (it’s around line 1200 but this may be different for each installation

If you have freeshipping, taxes then you will need to apply the following change:-

<totals>
<nominal>
<class>sales/quote_address_total_nominal</class>
<before>subtotal</before>
</nominal>
<subtotal>
<class>sales/quote_address_total_subtotal</class>
<after>nominal</after>
<before>grand_total</before>
</subtotal>
<shipping>
<class>sales/quote_address_total_shipping</class>
<after>subtotal,freeshipping,tax_subtotal,msrp</after>
<before>grand_total</before>
</shipping>
<grand_total>
<class>sales/quote_address_total_grand</class>
<after>subtotal</after>
</grand_total>
<msrp>
<class>sales/quote_address_total_msrp</class>
<before>grand_total</before>
</msrp>
</totals> </code>

I have bolded the 2 things that need to be done which are:-

(1) add ,msrp about tax_subtotal
(2) add <before>grand_total</before>