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 proposed `raw` 
to indicate that.  That would mean:

```php
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 accessible
```

The take-away for the asymmetric visibility only case is that we would need to 
use `raw` instead of `set`, 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 a `raw` keyword.


I've read through that explanation three times, but don't understand why the C#-style syntax would require to differentiate between `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

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php

Reply via email to