> On 26 Oct 2014, at 19:16, Rowan Collins <rowan.coll...@gmail.com> wrote:
> 
> I just had a thought on both the naming and future-proofing concerns of this 
> proposal: what about pre-emptively reserving the skeleton of the syntax 
> needed for accessors, without actually implementing them?

I’ve been thinking about this. While `public readonly $foo;` does work, it is 
confusing (only readonly to public) and limiting (no public/private option). 
Plus, while it could work with getters/setters, it’s hardly ideal.

On the other hand, while having C#-style syntax here gives us a full feature 
set, I don’t like that it inverts the order of a declaration. To show you what 
I mean, here’s a normal property:

    public $foobar;

Now, here’s a property with C#-style syntax:

    var $foobar { public get; private set; };

See how the `public` moved to the right? I don’t like that, I want to avoid 
that if possible. I’m all for C#-style syntax with the get and set, but I don’t 
like that it moves the visibility specifier.

Similarly, I don’t like this either:

    public $foobar { get; private set; }

Now the visibility is on both sides! Yuck. That’s the worst of both worlds.

What I’d like is probably something like this:

    public/private $foobar;

Tentative syntax. But this way, the visibility stays on the left. I think 
that’s good for readability. If you omit the second specifier, then the first 
one applies to getting and setting, as now. If you include it, the first one 
applies to getting, the second one to setting.

It’d also be compatible with properties, too:

    public/private $foobar {
        get { return $this->bar * $this->foo; }
        set($value) { $this->bar = $value / $this->foo; }
    }

It doesn’t prevent truly read-only properties, either:

    public $foobar {
        get { return $this->bar * $this->foo; }
    }

Does this sound like a good idea? A similar idea came up in the discussions 8 
years ago on readonly.

--
Andrea Faulds
http://ajf.me/





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

Reply via email to