Re: Readonly properties - immutability by default

From: Date: Sat, 17 Jul 2021 14:57:53 +0000
Subject: Re: Readonly properties - immutability by default
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-115454@lists.php.net to get a copy of this message
I don't think the way it is going to be realeased is elegant solution On Sat, Jul 17, 2021, 2:47 PM Andreas Leathley <a.leathley@gmx.net> wrote: > On 16.07.21 09:06, Nikita Popov wrote: > > We cannot make properties readonly by default, because that would be a > > major backwards compatibility break. > > > > If you're going for brevity, something you can do is omit the visibility > > specifier, as it is public by default. "readonly int $prop" works. > > Would it be possible to adapt constructor property promotion to support > this (as far as I tell, it currently does not)? Namely: > > class A { > public function __construct( > readonly int $id, > ) { > } > } > > According to the constructor property promotion RFC, the promotion only > happens when public, private and protected is used for an constructor > parameter. With the readonly RFC accepted, it would make sense to also > do constructor property promotion when readonly is used, to avoid the > explicit public, because readonly would also clearly define the > parameter as not-only-a-parameter. > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php > >

« previous php.internals (#115454) next »