Skip to content
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

Create ReflectionReadonlyProperty from their declaring class so their value can be set #10666

Merged
merged 4 commits into from
May 12, 2023

Conversation

MatTheCat
Copy link
Contributor

@MatTheCat MatTheCat commented May 1, 2023

Fixes #10049 and supersedes #10059.

I must have missed an RFC because from https://wiki.php.net/rfc/readonly_properties_v2#reflection

ReflectionProperty::setValue() can bypass the requirement that initialization occurs from the scope where the property has been declared.

But that does not seem to be the case. This makes ReflectionReadonlyProperty::setValue() crash when hydrating an inherited readonly property.

This PR makes ClassMetadataInfo build ReflectionReadonlyProperty with a property whose class is its declaring one to avoid this issue.

@MatTheCat MatTheCat force-pushed the inherited-readonly-properties branch 2 times, most recently from c30d469 to f2e335a Compare May 1, 2023 20:31
@mpdude
Copy link
Contributor

mpdude commented May 5, 2023

You can keep the entity classes and functional tests in a single file, other tests do this as well.

Personally, I find it much easier to understand tests when everything is in a single place.

@MatTheCat
Copy link
Contributor Author

MatTheCat commented May 6, 2023

Done; how can I make the CI green for PHP < 8.1?

@MatTheCat MatTheCat force-pushed the inherited-readonly-properties branch from 200cb89 to 2261433 Compare May 6, 2023 07:38
@MatTheCat MatTheCat force-pushed the inherited-readonly-properties branch from 2261433 to 6a3c091 Compare May 6, 2023 15:36
@MatTheCat MatTheCat changed the base branch from 2.14.x to 2.15.x May 6, 2023 15:37
@MatTheCat MatTheCat force-pushed the inherited-readonly-properties branch from 6a3c091 to 181460b Compare May 7, 2023 17:06
@MatTheCat
Copy link
Contributor Author

Okay I followed #10683 (comment)

Not sure about the naming though, feel free to suggest.

@MatTheCat MatTheCat force-pushed the inherited-readonly-properties branch from 181460b to b5647c5 Compare May 7, 2023 17:18
greg0ire
greg0ire previously approved these changes May 7, 2023
@MatTheCat MatTheCat force-pushed the inherited-readonly-properties branch from c3d6594 to 1c8d296 Compare May 7, 2023 20:29
greg0ire
greg0ire previously approved these changes May 7, 2023
@mpdude
Copy link
Contributor

mpdude commented May 8, 2023

Sorry when I caused too much confusion by asking for keeping everything in a single file 👌🏻

@greg0ire
Copy link
Member

greg0ire commented May 8, 2023

No worries, in the end it resulted in a better directory layout for tests IMO.

@MatTheCat MatTheCat force-pushed the inherited-readonly-properties branch from 1c8d296 to 2f46e5a Compare May 11, 2023 07:36
@greg0ire greg0ire added the Bug label May 11, 2023
@greg0ire greg0ire added this to the 2.15.2 milestone May 12, 2023
@greg0ire greg0ire merged commit cef1d2d into doctrine:2.15.x May 12, 2023
@greg0ire
Copy link
Member

Thanks @MatTheCat !

@MatTheCat MatTheCat deleted the inherited-readonly-properties branch May 12, 2023 06:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PHP readonly properties and inheritance cause error on hydration
4 participants