ObjectAccess uses always 'getProperty' method when accessed object has '__call' magic method #1169
Description
Description
If an (repository) object has the __call magic method, then all methods are automatically callable, and ObjectAccess tries to retrieve the value always with the get[PropertyName] method, instead of the is[PropertyName] or has[PropertyName]
I encountered the problem when using the TranslatableTrait for RepositoryObjects
I'm not sure if this is the intended behavior, but it effectively prevents the reliable use the 'is' and 'has' prefix as property getters. The problem can be fixed adding an additional check in initializePropertyGetterCache()
:
from
if (is_callable([$subject, $getterMethodName])) {
to
if (method_exists($subject, $getterMethodName) && is_callable([$subject, $getterMethodName])) {
Steps to Reproduce
- add (boolean) property
blah = true
and getter isBlah() to an object - Add
__call
magic method to object where ObjectAccess should retrieve a property value - Call
ObjectAccess::getProperty($object, 'blah');
Expected behavior
the call should return true
Actual behavior
it returns null, since it tries to get the value via getBlah()
Affected Versions
all versions using the actual repository