On Sun, Aug 7, 2022, at 3:46 PM, Ollie Read wrote:
> 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* I'm not wild about implicit ordering as a syntax, for two main reasons: 1) It requires implicit knowledge on the part of the reader what's going on. Any kind of explicit syntax makes it clear "public, except for this operation". ("this operation" for now being just set, but then the set is right there and self-documenting.) 2) It makes extending it to other operations like "once" or "init" in the future impossible. (See Future Scope.) If we went with public, private string $foo, which implicitly meant "public(get), private(set)", and then in the future we add a "once" operation to mimic the behavior of readonly... what would that look like? With (set), it's self-evident how to extend the syntax. With it being fully implicit, I cannot think of a way to do so. Something like public private:set (colon instead of parens) would work just as well, if the () are confusing somehow, but that doesn't feel like a common problem. And it would lose the parallelism with Swift. --Larry Garfield -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: https://www.php.net/unsub.php