Skip to content

Conversation

arnaud-lb
Copy link
Member

@arnaud-lb arnaud-lb commented Oct 21, 2024

This is a bug fix for a design flaw in the Lazy Objects Reflection API:

The API provides ReflectionProperty::setRawValueWithoutLazyInitialization() and ReflectionProperty::skipLazyInitialization(), but does not provide any way to fetch the value of a property without triggering initialization, or to check if a property is lazy.

A workaround is to cast the object as array (with (array) $obj), but this is slower than needed and is used in performance-critical code in Doctrine, for instance.

This PR fixes this by adding the methods ReflectionProperty::getRawValueWithoutLazyInitialization(object $obj) and `ReflectionProperty::isLazy(object $obj).

getRawValueWithoutLazyInitialization() returns NULL if the property is lazy, and behaves like getRawValue() otherwise.

@arnaud-lb arnaud-lb changed the base branch from master to PHP-8.4 October 21, 2024 12:48
@arnaud-lb arnaud-lb force-pushed the get-raw-without-init branch 2 times, most recently from 8572eb5 to 4ea3307 Compare October 21, 2024 12:58
…nitialization(), ReflectionProperty::isLazy()
@arnaud-lb arnaud-lb force-pushed the get-raw-without-init branch from 4ea3307 to 9d94999 Compare October 23, 2024 10:43
@arnaud-lb arnaud-lb changed the title Fix Lazy Objects Reflection API: add ReflectionProperty::getRawValueWithoutLazyInitialization() Fix Lazy Objects Reflection API: add getRawValueWithoutLazyInitialization(), isLazy() Oct 23, 2024
@arnaud-lb arnaud-lb closed this Oct 23, 2024
@arnaud-lb
Copy link
Member Author

Closed in favor of # 16342.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant