Re: [RFC] [PROPOSAL] Immutable/final/readonly properties

From: Date: Fri, 14 Feb 2020 13:30:35 +0000
Subject: Re: [RFC] [PROPOSAL] Immutable/final/readonly properties
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-108572@lists.php.net to get a copy of this message
On Fri, Feb 14, 2020 at 2:23 PM Máté Kocsis <kocsismate90@gmail.com> wrote: > > So far, my biggest question (apart from the name) have been how non-typed > properties should behave: as they are implicitly initialized to null if > they don't have an explicit default value (while typed properties remain > uninitialized), further modifications would be impossible to do on them - > which would make non-typed final properties almost useless. Nikita > suggested to just avoid their initialization, but I'd be curious about > other ideas as well. > Considering that PHP 8 will have union types, adding un-typed properties support seems like a waste of time. If somebody really wants a mixed property to be immutable, they could write `private immutable null|bool|int|float|string|array|object $property;`. That would make implementation straightforward, since you'd expect immutable to be before a type declaration (can be done in the parser, right?). Marco Pivetta http://twitter.com/Ocramius http://ocramius.github.com/

« previous php.internals (#108572) next »