Re: [RFC] Static property asymmetric visibility
| From: | Larry Garfield | Date: | Tue, 26 Nov 2024 20:35:29 +0000 |
| Subject: | Re: [RFC] Static property asymmetric visibility | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-126066@lists.php.net to get a copy of this message | ||
On Tue, Nov 26, 2024, at 3:57 AM, Tim Düsterhus wrote:
> Hi
>
> Am 2024-11-25 17:52, schrieb Larry Garfield:
>> Static property asymmetric visibility was left out of the original RFC,
>> because it seemed like it would be hard and of little use. Turns out,
>> Ilija found a way to make it easy. (Ilija is smart.) So here's a
>> small RFC to add aviz to static properties, because we can't think of a
>> reason to NOT do so.
>>
>> https://wiki.php.net/rfc/static-aviz
>
> The RFC has the status “Draft” and does not appear to be linked in the
> overview at https://wiki.php.net/rfc. Is it intended to be open
> for
> discussion yet?
Paperwork oversight on my part. Fixed now, thanks.
> Regarding the RFC contents: I am not sure the behavior of
>
private(set)
> implying final is obvious for static properties. Consider this
> example
> (https://3v4l.org/bvQjM):
>
> <?php
>
> class Foo {
> public static $baz;
> }
>
> class Bar extends Foo {
> public static $baz;
> }
>
> Foo::$baz = '2';
> Bar::$baz = '1';
> var_dump(Foo::$baz, Bar::$baz);
>
> Non-static properties only have $this-> for property access,
> but with
> static properties you can distinguish between self:: and
> static::,
> which makes overriding a private(set) static property
> meaningful,
> because they are actually independent properties.
>
> Best regards
> Tim Düsterhus
Hm, interesting point. I am not sure of the best way to model that.
Thinking aloud, my expectation would be that it behaves similarly to how final static methods would
behave. Which appears to be a syntax error: https://3v4l.org/j8mp0#v8.4.1
So, shouldn't properties do the same?
--Larry Garfield