Re: [RFC] Fix inconsistent behavior of $this variable
| From: | Rowan Collins | Date: | Tue, 24 May 2016 09:57:24 +0000 |
| Subject: | Re: [RFC] Fix inconsistent behavior of $this variable | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-93482@lists.php.net to get a copy of this message | ||
On 24/05/2016 06:45, Jesse Schalken wrote:
I'm curious, what is it about $this that makes it special in the first place? Can't it be a normal local variable that happens to already be assigned at the start of a method?There are a few things that take advantage of its specialness, e.g. - binding a closure to an object changes the meaning of $this in a way very different from assigning it into scope with "use($this)" - a method declared static can detect and throw errors on anything referencing $this - when calling parent::foo() from an instance method, the value of $this needs to be set appropriately on the new method; being able to reassign $this could lead to some odd behaviour there Python's approach is certainly valid, and leads to some different useful properties, I'm sure, but it's a very different design, not just a more relaxed attitude to assignment. Regadrds, -- Rowan Collins [IMSoP]