On Sun, Aug 7, 2022, at 9:38 PM, Rowan Tommins wrote:
> 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]
> 
> -- 
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: https://www.php.net/unsub.php
> 
> 

Just to throw in my ten cents:

I'm not sure if this is because I was recently reading about the fact that PHP 
doesn't have proper support for a comma operator, but I quite like the idea of 
providing them as a comma-separated list.

// Public for get and set
public int $number

// Public get, private set
public, private int $number

If a single visibility is provided, same old same old, but if two are provided, 
they are in the order of get, followed by set. While not being as verbose as 
providing (set) or other markings to differentiate them, it feels more natural, 
and it doesn't overcomplicate it.

---
Best Regards,
*Ollie Read*

Reply via email to