Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Serializer] Fixreadonly property initialization from incorrect scope#61028

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation

@santysisi
Copy link
Contributor

@santysisisantysisi commentedJul 2, 2025
edited
Loading

QA
Branch?6.4
Bug fix?yes
New feature?no
Deprecations?no
IssuesFix#60846
LicenseMIT

Readonly properties couldn't be initialized during denormalization due to scope restrictions. This change checks if a property isreadonly and uninitialized, if so, it sets the value using the declaring class's scope.

Also added a safety check to throw aLogicException if areadonly property is already initialized, to avoid accidental mutation.

@carsonbotcarsonbot added this to the6.4 milestoneJul 2, 2025
@santysisisantysisiforce-pushed thefix/readonly-property-initialization branch 5 times, most recently from2f87dc4 to5c28257CompareJuly 3, 2025 00:10
}

$reflectionProperty->setValue($object,$value);
if (!$reflectionProperty->isReadOnly()) {

Choose a reason for hiding this comment

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

I suppose we should deal with asymmetric visibility also?

santysisi reacted with heart emoji
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Thanks for pointing that out!

I tested the current implementation using properties with asymmetric visibility in PHP 8.4 and everything works as expected. The values are correctly set usingReflectionProperty::setValue() without throwing errors.

I believe this is because, starting from PHP 8.4.0,ReflectionProperty::setValue() still bypasses visibility restrictions (including asymmetric ones)

To make this explicit, I’ve added some tests that cover this behavior specifically for PHP 8.4.

Let me know if you'd prefer a stricter approach that checks write visibility explicitly.

@santysisisantysisiforce-pushed thefix/readonly-property-initialization branch from5c28257 tocaee87aCompareJuly 7, 2025 23:03
@santysisisantysisiforce-pushed thefix/readonly-property-initialization branch fromcaee87a to79c2ea6CompareJuly 7, 2025 23:23
@OskarStarkOskarStark changed the title[Serializer] Fix readonly property initialization from incorrect scope[Serializer] Fixreadonly property initialization from incorrect scopeJul 8, 2025
@nicolas-grekas
Copy link
Member

Thank you@santysisi.

santysisi reacted with hooray emojisantysisi reacted with heart emojisantysisi reacted with rocket emoji

@nicolas-grekasnicolas-grekas merged commitd524bc9 intosymfony:6.4Jul 9, 2025
11 checks passed
This was referencedJul 31, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@dunglasdunglasdunglas approved these changes

@nicolas-grekasnicolas-grekasnicolas-grekas approved these changes

@mtarldmtarldmtarld approved these changes

Assignees

No one assigned

Projects

None yet

Milestone

6.4

Development

Successfully merging this pull request may close these issues.

5 participants

@santysisi@nicolas-grekas@dunglas@mtarld@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp