Re: [RFC][Vote] Asymmetric Visibility

From: Date: Tue, 10 Jan 2023 18:29:00 +0000
Subject: Re: [RFC][Vote] Asymmetric Visibility
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-119255@lists.php.net to get a copy of this message
On Tue, Jan 10, 2023 at 11:19 AM Thomas Nunninger <thomas@nunninger.info> wrote: > I doubt, there would be any need for readonly if we would have had > asymmetric visibility first. And (using asymmetric visibility) I assume, > developers should be able to ensure that a property is 1. only > initialized once, 2. inside the limited scope of a class, and 3. not > overwritten during the lifetime of the object. I'd be interested in a > use case where you would really like to ensure this on the engine level. > > To go one step further, I would even ask the heretical question if we > should discourage/deprecate readonly once we have asymmetric visibility. > ;-) > I disagree. They serve different use cases. In the case of readonly, it's an easy way to also define _immutable_ classes. Aviz doesn't provide that; in fact, it is a way to explicitly allow use cases where changes can be made, while still providing direct access to a property. Yes, you _could_ add logic to a class to prevent changes after initialization... but marking a property as readonly does that for you, in a way that is less error prone than userland logic. -- Matthew Weier O'Phinney mweierophinney@gmail.com https://mwop.net/ he/him

« previous php.internals (#119255) next »