On 1/20/2013 3:11 PM, Gordon Oheim wrote:
Am 17.01.2013 19:20, schrieb Clint Priest:
I'm happy to say that Property Accessors is ready for a vote for
inclusion in 5.5 release.

Nikita and I (as well as Stas a bit) have all been working hard to make
this happen for 5.5, voting and the specifications are here:

https://wiki.php.net/rfc/propertygetsetsyntax-v1.2#voting

Thanks,

-Clint

Thanks Clint and Niki for your work. Sorry to respond only now that the voting process has already started. I usually don't follow/participate on internals due to the noise and poisoned atmosphere (but that's a different story). Also thanks Niki for taking the time to answer all my questions I had about this beforehand.

My main issue with the implementation at hand is the weird way in which we allow the visibility on the properties to be declared, e.g.

    public $foo { get; protected set; }

The visibility keyword on the property is watering down the visibility semantics. Either the property is public (then it can be set) or it is not public. I would have much less of a problem with this, if declaring visibility on a property could only be loosened but not tightened. That would at least be consistent with how visibility works with inheritance. It would be much better though to remove the visibility keyword from the property altogether. It almost never tells the truth.

This is basically an argument against asymmetrical visibility altogether which is one of the most useful features of this proposal. I think there are many use cases where an object wants to be able to emit a message (value) but not receive one and being able to declare that fact is important.

Removing the visibility keyword from the property altogether would also remove the purported default visibility that is applied to the accessors. I say "purported" because doing

    public $foo { get; protected set; }

will also change the unset accessor to protected, which makes perfect sense when you think about it but is completely unobvious when the declaration claims the default visibility of all accessors to be public. The default visibility of isset is that of get and the default visibility of unset is that of set instead.

To add to the confusion, doing

    public $foo { get; protected set; public unset; }

WILL work and change the visibility of unset back to what the property claims it is. This should not be necessary when visibility on the keyword defines the default visibility. I guess it's safe to say that having the visibility on the property does very little to express anything meaningful about the property or the default visibility of *all* the accessors.

Perhaps this is just a documentation problem in that somewhere the implication that public applies to all accessors when it should really say that it applies to all declared accessors.

It is perfectly logical that when you cannot set a value, then you cannot unset a value.

Defining what you have done above is declaring that you want to allow people to get or unset the value, but not set it directly. This makes sense in some usage scenarios. As an example, perhaps $foo represents an internally generated id which is generated on the first call to the getter, you don't want outsiders to specify the id, but you're okay with having it unset so that a new one can be generated with the internal generation mechanics on the next get request.

As an aside, your previous example can also be declared like this:
    public $foo { get; protected set; unset; }

unset is explicitly declared and implicitly implemented and is public, isset would be implicitly declared and implicitly implemented and follow the visibility of the getter.

isset/unset only follow the get/set visibility if isset/unset are left undeclared.

If this could be changed, I'd be more willing to vote pro the proposal.

TL;DR: The visibility keyword on the property is almost never giving an accurate information about the accessor visibility. Thus, it should be removed or replaced for clarity's sake.

I think I've made the case above that this isn't accurate, it always affects declared accessors which do not have their own visibility specified.


Regards,
Gordon


--
-Clint

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

Reply via email to