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

[PropertyAccess] Readonly properties must have no PropertyWriteInfo #48108

Conversation

CasvanDongen
Copy link
Contributor

Q A
Branch? 5.4
Bug fix? yes
New feature? no
Deprecations? no
Tickets -
License MIT
Doc PR -

The reported WriteInfo of readonly promoted properties is incorrectly returned as a writeable property when constructor extraction is disabled. This PR fixes that by correctly returning PropertyWriteInfo::TYPE_NONE when enable_constructor_extraction is false.

Obviously, this fix only applies to PHP8.1 or higher.

@carsonbot
Copy link

Hey!

I see that this is your first PR. That is great! Welcome!

Symfony has a contribution guide which I suggest you to read.

In short:

  • Always add tests
  • Keep backward compatibility (see https://symfony.com/bc).
  • Bug fixes must be submitted against the lowest maintained branch where they apply (see https://symfony.com/releases)
  • Features and deprecations must be submitted against the 6.2 branch.

Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change.

When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor!
If this PR is merged in a lower version branch, it will be merged up to all maintained branches within a few days.

I am going to sit back now and wait for the reviews.

Cheers!

Carsonbot

@CasvanDongen CasvanDongen changed the title [PropertyAccess] Promoted readonly properties must have no PropertyWriteInfo [PropertyInfo] Promoted readonly properties must have no PropertyWriteInfo Nov 4, 2022
@carsonbot
Copy link

Hey!

I think @Tomanhez has recently worked with this code. Maybe they can help review this?

Cheers!

Carsonbot

@CasvanDongen
Copy link
Contributor Author

@dunglas or @nicolas-grekas is it possible to review this PR?

@carsonbot carsonbot changed the title [PropertyInfo] Promoted readonly properties must have no PropertyWriteInfo [PropertyAccess] Promoted readonly properties must have no PropertyWriteInfo Apr 4, 2023
@nikophil
Copy link
Contributor

nikophil commented Apr 4, 2023

@dunglas @nicolas-grekas any chance to see this merged? 🙏

@nicolas-grekas nicolas-grekas changed the title [PropertyAccess] Promoted readonly properties must have no PropertyWriteInfo [PropertyAccess] Readonly properties must have no PropertyWriteInfo Apr 17, 2023
@@ -397,8 +397,11 @@ public function getWriteInfo(string $class, string $property, array $context = [

if ($reflClass->hasProperty($property) && ($reflClass->getProperty($property)->getModifiers() & $this->propertyReflectionFlags)) {
$reflProperty = $reflClass->getProperty($property);
if (\PHP_VERSION_ID < 80100 || (false === $reflProperty->isReadOnly() && false === $reflProperty->isPromoted())) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I remove the part about $reflProperty->isPromoted() (which I just did and pushed), tests still pass. This makes me wonder what how this relates to property promotion? Isn't this only about readonly?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's my mistake. I've missed the part that readonly properties in the constructor are automatically promoted. The change above indeed is correct.

@nicolas-grekas nicolas-grekas force-pushed the property-accessor-php-81-writemutator-readonly-promoted-properties branch from d0d1096 to 813b950 Compare April 17, 2023 13:42
@nicolas-grekas nicolas-grekas force-pushed the property-accessor-php-81-writemutator-readonly-promoted-properties branch from 813b950 to 2aa6c7d Compare April 17, 2023 14:20
@nicolas-grekas
Copy link
Member

Thank you @CasvanDongen.

@nicolas-grekas nicolas-grekas merged commit af5b340 into symfony:5.4 Apr 17, 2023
6 of 9 checks passed
This was referenced Apr 28, 2023
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.

None yet

4 participants