[PHP-DEV] static properties in readonly classes

Hello internals,

As far as I can tell from previous conversations and PRs; static properties aren’t supported in readonly classes for technical reasons and because nobody was sure what to do with them …

… but that seems weird because you can also do something like this: https://3v4l.org/uYNQD to hack your way around it if you want a mutable static state encapsulated in the class.

So, I would like to propose a question: should readonly classes be allowed to have static properties? And if so, should they be allowed to be mutable? Or rather, should the static keyword also be prevented from being used in readonly class methods?

It just feels weird to say that “static properties aren’t allowed, but you can create static properties by embedding them in a method!” In other words, it feels inconsistent.

— Rob

On 8 Jun 2025, at 15:12, Rob Landers <rob@bottled.codes> wrote:

Hello internals,

It just feels weird to say that "static properties aren’t allowed, but you can create static properties by embedding them in a method!" In other words, it feels inconsistent.

— Rob

To me it feels like it’s working as intended. Similar to private properties being accessible via reflection. The syntax is well designed for the natural flow, but if you want to break the warranty seal go nuts.