Skip to content

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

Closed
wants to merge 3 commits into from

Conversation

arnaud-lb
Copy link
Member

@arnaud-lb arnaud-lb commented Oct 10, 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 method ReflectionProperty::isLazy(object $obj). It returns true when the property is lazy and accessing it would trigger initialization of the object.

@arnaud-lb arnaud-lb changed the base branch from master to PHP-8.4 October 10, 2024 14:31
@beberlei
Copy link
Contributor

@arnaud-lb seeing it so closely to the isInitialized method, maybe your idea with isLazy is better to avoid confusion with the initialized / uninitialized concept for readonly properties.

@bukka
Copy link
Member

bukka commented Oct 11, 2024

you cannot target 8.4 as we no longer allow any features in RC.

@arnaud-lb arnaud-lb changed the base branch from PHP-8.4 to master October 17, 2024 15:33
@arnaud-lb arnaud-lb changed the base branch from master to PHP-8.4 October 23, 2024 11:16
@arnaud-lb arnaud-lb changed the title Add ReflectionProperty::isUninitializedLazy() Fix Lazy Objects Reflection API: add ReflectionProperty::isLazy() Oct 23, 2024
Copy link
Contributor

@nicolas-grekas nicolas-grekas left a 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 🙏

@arnaud-lb
Copy link
Member Author

@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.

@NattyNarwhal
Copy link
Member

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.

@ericmann
Copy link
Contributor

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.

@bukka
Copy link
Member

bukka commented Oct 23, 2024

It's a bit questionable whether this is a bug but if others think it is, I don't have objections.

@arnaud-lb arnaud-lb marked this pull request as ready for review October 24, 2024 13:59
@arnaud-lb arnaud-lb requested a review from kocsismate as a code owner October 24, 2024 13:59
@arnaud-lb arnaud-lb closed this in 54a40f3 Oct 31, 2024
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.

7 participants