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]
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php