Hi all,
At compile time, the engine detects whether $this is used in an op
array (using opline_is_fetch_this()). If so, it sets the flag
op_array->uses_this.
At the start of each execute loop, if this flag is set and a context
object is available, a reference to the context object is added to the
locals map. Thus the userspace $this reference is created.
Problem is, the compile time check does not detect dynamic uses of
$this, resulting in inconsistent behaviour in several areas, such as:
--> When using get_defined_vars()
.
--> When accessing $this as a variable variable.
Illustration here: http://pastebin.ca/920973
This could be solved by creating $this regardless of the
op_array->uses_this flag - i.e. only if an appropriate context object
has been set.
Simple patch: http://pastebin.ca/920986.
I tried it, and it only breaks one test:
Zend\tests\get_defined_vars.phpt (with the patch, get_defined_vars()
shows $this, which is arguably the correct behaviour).
So the compile-time decision to avoid adding $this as a local
userspace variable clearly has disadvantages. What are the advantages?
If it's for performance only, is the optimisation worth the
inconsistency that it causes?
Regards,
Robin
Hello Robin,
This interesting issue, this should be patched asap!
Vote +1.
Best Regards, Dimitar Isusov