Re: Request Feedback for Instance Variable Sugar RFC

From: Date: Wed, 11 Mar 2015 13:03:14 +0000
Subject: Re: Request Feedback for Instance Variable Sugar RFC
References: 1 2 3 4 5 6 7 8 9 10 11 12 13  Groups: php.internals 
Request: Send a blank email to internals+get-84541@lists.php.net to get a copy of this message
Johannes Ott wrote on 10/03/2015 20:46:
okay indeed the dynamic properties are a problem I didn't think about on my suggestion. Without the wish to hijack this thread for another typesafety discussion, I must say again that PHP needs a less dynamic and more declaratively properties concept in my opinion.
Yes, I think a standard way to say that a particular object has strictly declared all its properties, and should not allow would be useful. (Even with that, though, I'd be against guessing that "$foo" meant "$this->foo"; it just makes code harder to read.)
So I would suggest for now to keep the $this variable, but to make it more similar to other OOP-languages I would suggest to remove the $-character in front. In my opinion it would fit better to other object keywords like parent and self as well.
Other OOP languages only don't have a sigil such as $ in front of this if they don't have one in front of *any* variable. Why should $this, which acts like a normal variable in pretty much every way, drop the $ when every other variable in the language has one? Note that the syntax of parent and self is different, and is consistent with static member/method access, or more strictly "scope resolution". You can't pass parent or self around as variables, only use them to resolve scopes, so they don't have a $. That's what sigils are for - making similar things look similar and distinct things look distinct. Regards, -- Rowan Collins [IMSoP]

« previous php.internals (#84541) next »