Skip to content

ObjectAccess uses always 'getProperty' method when accessed object has '__call' magic method #1169

Open
@uris-dev

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

  1. add (boolean) property blah = true and getter isBlah() to an object
  2. Add __call magic method to object where ObjectAccess should retrieve a property value
  3. 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

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions