[php-src] PR #22609: Improved `readonly` errors
| From: | NickSdot | Date: | Sun, 05 Jul 2026 15:38:26 +0000 |
| Subject: | [php-src] PR #22609: Improved `readonly` errors | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-36851@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/22609
Author: NickSdot
This surfaced via https://github.com/php/php-src/pull/22588 see
https://github.com/php/php-src/pull/22588#discussion_r3523422058.
There are two commits. The second one is redoing the first one. Tim asked me in the linked comment
to add
public(set) to a readonly property. There are definitely other
tests doing that, and I went ahead with it. Though, it seems very weird to me that we would have to
use public(set) to override the implicit protected(set) from
readonly, just to then surface the actual error.
I am not going to pretend I understand all the complexity involved here... But the current state of
the PR seems more logical to me because we no longer need public(set), and get actual
helpful errors:
> Fatal error: Readonly property C::$prop cannot implement set hook required by interface
> I::$prop in %s on
> Fatal error: Readonly property C::$prop cannot implement set hook required by class A::$prop in
> %s on line %d
instead of only changing:
> Fatal error: Set access level of C::$prop must be omitted (as in class I) in %s on line %d
to:
> Fatal error: Set access level of readonly property C::$prop is protected(set), but must be
> public(set) (as in interface I) in %s on line %d
as the first commit did. This would make tests pass, but it's not honest because in combination
with readonly the actual problem is not visibility. Not fully sure if it would be
semantically defensible, but I think we could argue that public(set) in combination
with readonly itself, on a promoted property, never should have worked and should have
errored -- because it achieves nothing. Anyway, too late to change that because it would be
breaking.
Fwiw, I know that a set interface property does not mean that the implementor must have
a hook -- however, since readonly is implicit protected, for a promoted property the
right conclusion seems to be to acknowledge that in this case the error **must be** related to
hooks. As mentioned above, changing visibility to public(set) does not achieve anything
other than reaching the actual error, and this will never change. However, it is possible that we
will find a solution for allowing hooked readonly properties in the future -- which is another
argument for having a hook related error, instead of a more generic one, until then
That said, it's not impossible that I am missing something, but changing the order as I did
here seems sound.
Aside: interface_get_set_readonly.phpt was renamed interface_readonly_get_set_promoted.phpt, not
deleted
---
@iluuu1994 you added the ["error message should be
improved"](https://github.com/php/php-src/commit/8df557ac42c8227d8e7573f6a3a8d799ef28e7cd#diff-3882964f114e2d32642dfbe1cf3cedc5bebb631df5f9c12c106fc9be91502558R4).
Can I please have your opinion on this?