Re: [RFC] Asymmetric Visibility, v2

From: Date: Wed, 05 Jun 2024 21:39:53 +0000
Subject: Re: [RFC] Asymmetric Visibility, v2
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-123528@lists.php.net to get a copy of this message
Hi Tim On Tue, Jun 4, 2024 at 7:54 PM Tim Düsterhus <tim@bastelstu.be> wrote: > > One thing that would get pretty wonky would be private-read properties: > Private property names are currently internally "mangled" to include the > class name. This allows to define the same private property in multiple > classes of an inheritance chain, without those classes needing to know > about the private properties of each other and making the addition and > removal of a private property not a BC break. For all intents and > purposes those private properties to not exist, unless you are the class > itself. > > I have no idea what the semantics of a public-write, private-read > property should be - and this problem is pretty similar to the > sibling-discussion about making private-set properties implicitly final, > because otherwise the semantics get wonky. > > I believe that the case of making a property public-write, private-read > is best left to a virtual set-only hook. Indeed. A private property with a more permissible set operation is the wrong approach. What we'd want here is a public property with a restricted get operation. This is not quite expressible with the current syntax. We'd need something like public private(get), or public $prop { private get; } with the C# equivalent. However, this is quite an edge case, and since it requires additional syntax I don't think it's something we should support without a specific use-case. You can emulate it with a set-only virtual property, if you really want to. Ilija

« previous php.internals (#123528) next »