Skip to content

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

@S0FTWEX

Description

@S0FTWEX

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions