Re: [RFC] Asymmetric visibility

From: Date: Sun, 07 Aug 2022 20:38:45 +0000
Subject: Re: [RFC] Asymmetric visibility
References: 1 2 3 4 5 6  Groups: php.internals 
Request: Send a blank email to internals+get-118371@lists.php.net to get a copy of this message
On 07/08/2022 11:54, Lynn wrote:
Reading "public private", "public protected", or "protected private" reads really weird public private(set) static self $property.
Interesting, it seems that you've unconsciously broken it up as "public private" followed by "(set)", rather than "public" followed by "private(set)". Perhaps it's because of the position of the parentheses, which do feel awkward to me at first glance. Would it read more naturally to you with different punctuation? public (private set) static self $property; Or: (public; private set) static self $property; Or: public private-set static self $property; On 05/08/2022 19:08, Matthew Weier O'Phinney wrote:
I'm wondering if this sort of behavior could be indicated via attributes instead? Something like #[PropertySetBehavior(PROPERTY_SET_PRIVATE)]. Attributes have the benefit of being separate from the property declaration, arguably more readable (one per line), and composable.
Attributes are no more intrinsically "separate" or "one per line" than keywords; the following would be perfectly valid with the RFC's proposed syntax: class Foo {    public private(set)
       static int|string $id;
} And the following would be valid with an attribute like you suggest: class Foo {    #[PropertySetBehavior(PROPERTY_SET_PRIVATE)] public static int|string $id; } Even a shorter attribute name would have the extra punctuation, and the restriction that it comes before the normal visibility keyword: class Foo {    #[PrivateSet] public static int|string $id; } Regards, -- Rowan Tommins [IMSoP]

« previous php.internals (#118371) next »