get_defined_vars() inconsistencies and op_array->uses_this

From: Date: Thu, 28 Feb 2008 12:48:14 +0000
Subject: get_defined_vars() inconsistencies and op_array->uses_this
Groups: php.internals 
Request: Send a blank email to internals+get-35847@lists.php.net to get a copy of this message
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

« previous php.internals (#35847) next »