Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP8 error: method_exists() now throws an exception if the first argument is not string|object #1539

Closed
S0FTWEX opened this issue Apr 9, 2021 · 1 comment
Labels
bug good first issue easy to solve issues PHP 8 Related to PHP8

Comments

@S0FTWEX
Copy link
Contributor

S0FTWEX commented Apr 9, 2021

Preconditions (*)

  1. OpenMage 20.0.8
  2. PHP 8.0.3

Steps to reproduce (*)

  1. In Admin Panel, go to System -> Configuration and save any configuration you like
  2. Configuration is not saved, page goes white blank with this error in log:

Uncaught TypeError: method_exists():
Argument #1 ($object_or_class) must be of type object|string, bool given in /app/code/core/Mage/Core/Model/App.php:1409
Stack trace:
#0 /app/code/core/Mage/Core/Model/App.php(1409): method_exists()
#1 /app/code/core/Mage/Core/Model/App.php(1383): Mage_Core_Model_App->_callObserverMethod()
#2 /app/Mage.php(517): Mage_Core_Model_App->dispatchEvent()
#3 /app/code/core/Mage/Core/Model/Abstract.php(515): Mage::dispatchEvent()
#4 /app/code/core/Mage/Core/Model/Abstract.php(383): Mage_Core_Model_Abstract->_afterSave()
#5 /app/code/core/Mage/Core/Model/Resource/Transaction.php(150): Mage_Core_Model_Abstract->save()
#6 /app/code/core/Mage/Adminhtml/Model/Config/Data.php(215): Mage_Core_Model_Resource_Transaction->save()

Actual result (*)

I have fixed it just like this:
edit the line 1409 in file /app/code/core/Mage/Core/Model/App.php from:

if (method_exists($object, $method)) {
to:
if (is_object($object) && method_exists($object, $method)) {

Saving system configuration is now working well.

@kiatng
Copy link
Contributor

kiatng commented Apr 10, 2021

Note that the error is not specific to saving the system configuration in backend, it is thrown from Mage::dispatchEvent(), in which the classdefined in the config.xml is invalid:

foreach ($events[$eventName]['observers'] as $obsName => $obs) {
$observer->setData(array('event'=>$event));
Varien_Profiler::start('OBSERVER: '.$obsName);
switch ($obs['type']) {
case 'disabled':
break;
case 'object':
case 'model':
$method = $obs['method'];
$observer->addData($args);
$object = Mage::getModel($obs['model']);
$this->_callObserverMethod($object, $method, $observer);
break;
default:
$method = $obs['method'];
$observer->addData($args);
$object = Mage::getSingleton($obs['model']);
$this->_callObserverMethod($object, $method, $observer);
break;
}

When the class cannot be created in $object = Mage::getModel($obs['model']); or $object = Mage::getSingleton($obs['model']); , $object = false.

@Sekiphp Sekiphp added the PHP 8 Related to PHP8 label Apr 14, 2021
@S0FTWEX S0FTWEX closed this as completed May 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug good first issue easy to solve issues PHP 8 Related to PHP8
Projects
None yet
Development

No branches or pull requests

4 participants