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->_validateFile()
#1 /home/admin/domains/store.com/public_html/dev/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/GalleryController.php(46): Varien_File_Uploader->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->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->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->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']);
}
}
}
2 Answers 2
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– sellio2015年12月09日 23:09:05 +00:00Commented Dec 9, 2015 at 23:09
-
this code work for me magento 1.9.2.4matinict– matinict2016年08月29日 06:25:10 +00:00Commented 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/37536Asitis– Asitis2016年08月30日 11:42:51 +00:00Commented Aug 30, 2016 at 11:42
-
Awesome...It's working fine for meRamesh Kumar– Ramesh Kumar2016年12月27日 20:05:47 +00:00Commented Dec 27, 2016 at 20:05
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– Andy2017年12月20日 11:47:40 +00:00Commented Dec 20, 2017 at 11:47
Explore related questions
See similar questions with these tags.