10

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']);
 }
 }
 }
Teja Bhagavan Kollepara
3,8275 gold badges33 silver badges69 bronze badges
asked Dec 9, 2015 at 0:12

2 Answers 2

35

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.

answered Dec 9, 2015 at 10:49
4
  • Cool, works 100% I hope Magento 1.9.2 doesn't have any other php 7 incompatibility. Thanks for help! Commented Dec 9, 2015 at 23:09
  • this code work for me magento 1.9.2.4 Commented Aug 29, 2016 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 Commented Aug 30, 2016 at 11:42
  • Awesome...It's working fine for me Commented Dec 27, 2016 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']);
Marius
199k55 gold badges431 silver badges837 bronze badges
answered Sep 27, 2016 at 5:57
1
  • simply re-compile rather than edit these temp files? Commented Dec 20, 2017 at 11:47

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.