Re: Request Feedback for Instance Variable Sugar RFC
| From: | Larry Garfield | Date: | Tue, 10 Mar 2015 03:24:54 +0000 |
| Subject: | Re: Request Feedback for Instance Variable Sugar RFC | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-84496@lists.php.net to get a copy of this message | ||
On 03/09/2015 04:26 PM, Rowan Collins wrote:
On 9 March 2015 09:43:32 GMT, Shawn McCool <shawn@heybigname.com> wrote:I concur. I don't see much advantage of a short hand in this case, but I would love to see someone pick up both the property RFC (which implied short-hand getter/setters) and shorthand constructors. (It's undoubtedly too late for 7.0, but they'd be great additions for 7.1.) --Larry GarfieldIn order to access instance variables, one must use theI disagree with this premise. The $this here is not just decorative syntax, it's an actual variable, which can be passed around just like any other variable. The -> is then the standard way of accessing a property or method, applied to that variable. This is beautifully simple, and expresses what's going on perfectly: if you look at $this->foo, and ask "which foo is being referenced here?", the answer is clearly "the one which is a property of $this". The only places I can see value in a shorthand are in constructors and setters, where you're just copying from one name to another ($this->foo = $foo). But the part that's redundant there is the variable/property names, not the $this, so what you need is getter/setter support, or shorthand constructors (you should be able to find previous RFCs for both). Regards,$this->prefix. The problem with this is that it reduces expressiveness in the language and increases the amount of unnecessary decoration, reducing readability.