Re: [RFC] Fix inconsistent behavior of $this variable
| From: | Rowan Collins | Date: | Tue, 24 May 2016 21:00:27 +0000 |
| Subject: | Re: [RFC] Fix inconsistent behavior of $this variable | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-93493@lists.php.net to get a copy of this message | ||
On 24/05/2016 20:21, Marc Bennewitz wrote:
As of $this is a very special variable where only the engine is (or should) be allowed to change. I would like to ask you if it wouldn't be better to NOT define $this as a special variable including a lot of code to make sure this variable doesn't get re-assigned but instead define this as a keyword like self where the syntax makes sure it can't be re-assigned and it's less special and simpler to learn for beginners.It's an interesting concept, but most of the time $this *does* behave like a variable - it's not just a way of accessing scope like "self". You can write "foo($this)", "$bar = $this", even "echo $this" (if __toString is defined). So any syntax that made it look unlike a variable would have the opposite learning problem - how come I can use it like a variable, but it looks like something else? There's also rather a shortage of syntax that doesn't already mean something... Regards, -- Rowan Collins [IMSoP]