How to make Magento work with PHP 5.3


Magento versions prior to 1.4 are not compatible with PHP 5.3, resulting in errors like the below:

Fatal error: Method Varien_Object::__tostring() cannot take arguments in /magento/lib/Varien/Object.php

The problem is that older version of Magento used some functions which were deprecated in PHP 5.3.

Upgrading Magento to the latest version will solve the problem permanently, however, that may be undesirable because templates needs to be updated, etc. This article explains the necessary changes to make Magento work with PHP 5.3. You can follow these steps to temporarily fix the problem while you prepare your store for an upgrade.

The solution

(All file paths referenced below are relative to your Magento root directory)

  1. In file lib/Varien/Object.php (line 484), replace

    public function __toString(array $arrAttributes = array(), $valueSeparator=',')
    by
    public function __invoke(array $arrAttributes = array(), $valueSeparator=',')
  2. In file app/code/core/Mage/Catalog/Model/Layer/Filter/Price.php (line 139), replace

    $key.= $taxReq->__toString(array(), '_');
    by
    $key.= $taxReq->__invoke(array(), '_');
  3. In file lib/Zend/Pdf/Resource/Image/Jpeg.php (line 59), replace

    if (!$gd_options['JPG Support'] ) {
    by
    if ( (!isset($gd_options['JPG Support']) || $gd_options['JPG Support'] != true) &&
    (!isset($gd_options['JPEG Support']) || $gd_options['JPEG Support'] != true) ) {

  4. In the following files:
    index.php
    downloader/index.php
    downloader/Maged/Pear.php
    lib/Varien/Pear.php

    Replace

    error_reporting(E_ALL | E_STRICT);
    by
    error_reporting(E_ALL & E_STRICT & ~E_DEPRECATED);

Now clear the cache and you should be able to use Magento with PHP 5.3!

Troubleshooting

Problem:

I get the error Can't retrieve entity config: core/store_group when accessing the Frontend.

Solution:

The error happens due to outdate SimpleXML library that is not compatible with PHP 5.4. Replace lib/Varien/Simplexml folder with the same folder from the latest Magento installation package.


Problem:

I get a blank page when I try to print any invoices or generate PDFs from the Admin Pane / error log shows following:

PHP Fatal error: Declaration of Zend_Pdf_FileParserDataSource_File::__construct() must be compatible with Zend_Pdf_FileParserDataSource::__construct()

Solution:

Edit lib/Zend/Pdf/FileParserDataSource.php, change: abstract public function __construct(); to abstract public function __construct($filePath);


Problem:

I get the error:
Unknown error (8192): Function split() is deprecated in /home/mascara/public_html/app/code/core/Mage/Core/Controller/Request/Http.php on line 199

Solution:

Edit app/code/core/Mage/Core/Controller/Request/Http.php, on line 199, change: $host = split(':', $_SERVER['HTTP_HOST']); to: $host = explode(':', $_SERVER['HTTP_HOST']);


Was this answer helpful?