Skip to content

ext/reflection: Make properties readonly - #24282

Merged
kamil-tekiela merged 1 commit into
php:masterfrom
kamil-tekiela:Reflection-readonly-properties
Oct 22, 2026
Merged

kamil-tekiela merged 1 commit into
php:masterfrom
kamil-tekiela:Reflection-readonly-properties

Conversation

@kamil-tekiela

@kamil-tekiela kamil-tekiela commented Oct 12, 2026 •

Copy link
Copy Markdown
Member

Fixes #24147 alternative to #24153

It should not break BetterReflection.

@kamil-tekiela

Copy link
Copy Markdown
Member Author

@ndossche According to the test, this should still allow unset, even though I think it would be better not too. The BC changes are minimal here: the properties cannot be redeclared. As such, I think it may even go on PHP 8.4.

@Ocramius What is your opinion on this?

@Ocramius

Copy link
Copy Markdown
Contributor

even though I think it would be better not too

An alternative could be to interface the properties, FWIW - requires some more substantial changes.

unset() is the only mechanism I currently know of to allow shadowing a property with additional logic: if property accessors allow overriding a parent property, that's also a viable idea.

@Ocramius

Copy link
Copy Markdown
Contributor

BTW, if you want, just take the phpunit suite of BetterReflection for a spin on this branch: it is very detailed

@kocsismate

Copy link
Copy Markdown
Member

These changes make sense to me, and I pretty much support this, but I don't think it should go into PHP 8.4, readonly shouldn't be added to a 2 year-old release IMO.

@kamil-tekiela
kamil-tekiela marked this pull request as draft October 20, 2026 12:34
@kamil-tekiela
kamil-tekiela changed the base branch from PHP-8.4 to master October 20, 2026 12:34
@kamil-tekiela
kamil-tekiela force-pushed the Reflection-readonly-properties branch from e319ba4 to 75d3fc9 Compare October 20, 2026 12:37
@kamil-tekiela
kamil-tekiela marked this pull request as ready for review October 20, 2026 12:37

@kocsismate kocsismate left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, but an upgrading note is warranted, isn't it?

@kamil-tekiela

Copy link
Copy Markdown
Member Author

LGTM, but an upgrading note is warranted, isn't it?

There is an upgrading note. Are you saying it's not needed?

@kocsismate

Copy link
Copy Markdown
Member

There is an upgrading note. Are you saying it's not needed?

Uh sorry, I thought that your force push only updated the branch (and didn't notice it when I quickly glimpsed the content through again). Then all good!

@kamil-tekiela
kamil-tekiela merged commit eef0f71 into php:master Oct 22, 2026
18 checks passed
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.

ReflectionProperty class and name properties are documented as Read-only, but they can be changed.

3 participants