8

I'm just testing Magento 1.9.2 with Php 7. All seemed to work, but suddenly I tried to upload image for the product. I got error like below:

Fatal error</b>:  Uncaught Error: Function name must be a string in /home/admin/domains/store.com/public_html/dev/lib/Varien/File/Uploader.php:259
Stack trace:
#0 /home/admin/domains/store.com/public_html/dev/lib/Varien/File/Uploader.php(180): Varien_File_Uploader-&gt;_validateFile()
#1 /home/admin/domains/store.com/public_html/dev/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/GalleryController.php(46): Varien_File_Uploader-&gt;save('/home/admin/dom...')
#2 /home/admin/domains/store.com/public_html/dev/app/code/core/Mage/Core/Controller/Varien/Action.php(418): Mage_Adminhtml_Catalog_Product_GalleryController-&gt;uploadAction()
#3 /home/admin/domains/store.com/public_html/dev/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(254): Mage_Core_Controller_Varien_Action-&gt;dispatch('upload')
#4 /home/admin/domains/store.com/public_html/dev/app/code/core/Mage/Core/Controller/Varien/Front.php(172): Mage_Core_Controller_Varien_Router_Standard-&gt;match(Object(Mage_Core_Controller in <b>/home/admin/domains/store.com/public_html/dev/lib/Varien/File/Uploader.php

Anybody know how to fix it?

Function affected in upload.php at line around 259

protected function _validateFile()
    {
        if ($this->_fileExists === false) {
            return;
        }

        //is file extension allowed
        if (!$this->checkAllowedExtension($this->getFileExtension())) {
            throw new Exception('Disallowed file type.');
        }
        //run validate callbacks
        foreach ($this->_validateCallbacks as $params) {
            if (is_object($params['object']) && method_exists($params['object'], $params['method'])) {
                $params['object']->$params['method']($this->_file['tmp_name']);
            }
        }
    }
33

http://php.net/manual/de/migration70.incompatible.php https://wiki.php.net/rfc/uniform_variable_syntax

Due to uniform variable syntax the code is now interpreted strictly from left to right.

The line

$params['object']->$params['method']($this->_file['tmp_name']);

should be

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

You can find a overview of all files to edit in this answer.

  • Cool, works 100% I hope Magento 1.9.2 doesn't have any other php 7 incompatibility. Thanks for help! – sellio Dec 9 '15 at 23:09
  • this code work for me magento 1.9.2.4 – matinict Aug 29 '16 at 6:25
  • This solution has all the files you'll need to edit for a good PHP7 performance: magento.stackexchange.com/a/105604/37536 – Alex Timmer Aug 30 '16 at 11:42
  • Awesome...It's working fine for me – Ramesh Kumar Dec 27 '16 at 20:05
2

In Addition to the answers above, don't forget to check the file:

\includes\src\Varien_File_Uploader.php on line 259

Replace

$params['object']->$params['method']($this->_file['tmp_name']);

with

$params['object']->{$params['method']}($this->_file['tmp_name']);
  • simply re-compile rather than edit these temp files? – Andy Dec 20 '17 at 11:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.