Re: [RFC] Asymmetric visibility
| From: | Tim Düsterhus | Date: | Wed, 31 Aug 2022 21:26:58 +0000 |
| Subject: | Re: [RFC] Asymmetric visibility | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-118548@lists.php.net to get a copy of this message | ||
Hi
On 8/31/22 22:43, Larry Garfield wrote:
## References make everything worse […] That problem wouldn't happen if all we're changing is visibility, however. That means in the C# style, we would need to differentiate whether the block on the right is intended to disable references or not. Ilija has proposedI've read through that explanation three times, but don't understand why the C#-style syntax would require to differentiate betweenrawto indicate that. That would mean:class Test { public $a { private set; } public $b { private raw; } public function inScope() { echo $this->a; // echo $this->getA(); $this->a = 'a'; // $this->setA('a'); echo $this->b; // echo $this->b; $this->b = 'b'; // $this->b = 'b'; } } $test = new Test(); echo $test->a; // echo $test->getA(); $test->a = 'a'; // Error, set operation not accessible echo $test->b; // echo $test->getB(); $test->b = 'b'; // Error, set operation not accessibleThe take-away for the asymmetric visibility only case is that we would need to userawinstead ofset, in order to avoid confusion later with accessor hooks and whether or not to disable references. The Swift-style syntax, as it does not require any hook-like syntax to just control visibility, does not have this problem. There is no ambiguity to resolve, so no need for arawkeyword.
set and raw. Isn't the difference between "visibility only" and "accessor" not clear [1] by having either '{' or ';' after the 'set'?
[1] Read: Clear to the engine, not talking about the human reader here.
Best regards
Tim Düsterhus