Re: [RFC] Asymmetric visibility

From: 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 proposed raw to 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 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

« previous php.internals (#118548) next »