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

From: Date: Wed, 19 Feb 2020 19:36:17 +0000
Subject: Re: [RFC] [DISCUSSION] Immutable/final/readonly properties
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-108688@lists.php.net to get a copy of this message
On Wed, Feb 19, 2020, 19:51 Larry Garfield <larry@garfieldtech.com> wrote: > On Wed, Feb 19, 2020, at 11:05 AM, Máté Kocsis wrote: > > Hi Internals, > > > > I'd like to move my RFC forward to the discussion phase: > > https://wiki.php.net/rfc/write_once_properties > > > > In short, I propose to add support for a new property modifier that would > > allow properties to be initialized, but not modified afterwards. > > > > Cheers, > > Máté Kocsis > > As envisoned, does this allow for a property to be set to a dynamic > value? My concern is that while a public locked/writeonce property is > great for access, it doesn't do anything to enable lazy setting on first > access. In fact the only way to do that would be to make it private and > wrap access in a method, which would look exactly like that does now but > with an extra keyword that doesn't actually offer much. > > You could set the value in advance in the constructor, but then it's not > lazy, just locked. > > Is there a way it could support lazy-on-first-use then locked? Máté did run a few teats: operating on a lazy value (before initialisation) seems to work as expected 👍

« previous php.internals (#108688) next »