Re: [RFC] Asymmetric visibility

From: Date: Sun, 07 Aug 2022 18:58:25 +0000
Subject: Re: [RFC] Asymmetric visibility
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-118368@lists.php.net to get a copy of this message
> Le 5 août 2022 à 19:08, Larry Garfield <larry@garfieldtech.com> a écrit : > > Ilija Tovilo and I are happy to present the first new RFC for PHP 8.3: Asymmetric Visibility. > > https://wiki.php.net/rfc/asymmetric-visibility > > Details are in the RFC, but it's largely a copy of Swift's support for the same. > > -- > Larry Garfield > larry@garfieldtech.com > Hi, I like the RFC, and in particular allowing property visibility to remain orthogonal to property accessors. There are few missing details in the RFC (which is otherwise good): 1. Are static properties supported? 2. What about properties that are overridden/redeclared in a subclass? Given that extending the visibility is generally allowed: ```php class A { protected int $x; } class B extends A { public int $x; // ok } ``` I expect that the following should be allowed as well: ```php class A { public protected(set) int $x; } class B extends A { public int $x; // ok } ``` On the other hand, I expect that the two following cases should *not* be allowed, because it would break encapsulation of class A: ```php class A { public private(set) int $x; } class B extends A { public int $x; // error: cannot change a private property to public (or protected) } ``` and: ```php class A { public private(set) int $x; } class B extends A { public private(set) int $x; // error: cannot make a private property in A as private in B } ``` —Claude

« previous php.internals (#118368) next »