-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Fix Lazy Objects Reflection API: add ReflectionProperty::isLazy() #16342
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
Conversation
@arnaud-lb seeing it so closely to the |
you cannot target 8.4 as we no longer allow any features in RC. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I missed this in the RFC because I used a hack based on (array)
. Definitely something that's missing and that'd be great even late in 8.4 🙏
@bukka after thinking more about this change, we would like to propose it as an API bug fix since this addresses a flaw in an API introduced in 8.4. @php/release-managers-84 do you accept this to be merged in 8.4 as a bug fix? NB: build failures are unrelated. |
Since it seems a polyfill could be used and documented, I'm not sure about rushing it into 8.4. However, it's very simple, self-contained, and fixes a problem with an 8.4 specific feature (as opposed to something general that 8.4 makes more obvious), so I think it should be fine. I'm wondering what the other RMs think. |
I have no objection. |
It's a bit questionable whether this is a bug but if others think it is, I don't have objections. |
This is a bug fix for a design flaw in the Lazy Objects Reflection API:
The API provides
ReflectionProperty::setRawValueWithoutLazyInitialization()
andReflectionProperty::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 method
ReflectionProperty::isLazy(object $obj)
. It returns true when the property is lazy and accessing it would trigger initialization of the object.