Hey Rowan,
On 29.06.26 16:00, Rowan Tommins [IMSoP] wrote:
On 29/06/2026 07:31, Nick Sdot wrote:
If "use conventional constructors, if you need `readonly` classes"
stands, then the same can be argued for everything else in the RFC.
For the record, my view is completely the opposite: if the new syntax
allows everything a normal constructor does, just in a slightly
different position, it will lead to endless style discussions of which
to use.
That's a fair opinion, and not unexpected. Personally, I oppose
introducing more inconsistencies to PHP. Looks like that we need to have
these discussions then?
In fact, I don't think even property hooks belong in a primary
constructor; they're ugly enough in a constructor promoted property.
It's a feature that was accepted to PHP and exists already. So it
doesn't really matter whether we (I agree -- shouldn't be used for
anything more than eg a neat callback) find it ugly and we have to deal
with its existence. You are basically making a point for allowing
primary constructor bodies. Having them allows to have a readonly
classes with primary constructors, and assign properties in their body.
Neat.
I think it's perfectly fine to have short-hands that only cover
specific use cases, and longer forms that let you express more complex
use cases. It's one of the reasons I voted against the recent RFC to
allow an extra reassignment of properties in the constructor
[https://wiki.php.net/rfc/promoted_readonly_constructor_reassign].
For the record, my view is completely the opposite: without allowing
primary constructor bodies the added value of adding the new syntax is
nearly non-existent.
Quoting from your message in the first thread to this:
I don't think we should add extra syntax to the language just to
change people's habits. If you want a constructor body as the first
thing in the class, you can do that right now.
...because the exact argument can be made from either point of view. To
quote you again: "all or nothing"; bodies should be allowed.
--
Cheers
Nick