# get_defined_vars() inconsistencies and op_array->uses_this

- Thread: https://externals.io/message/35847
- Original archive: https://news-web.php.net/php.internals/35847
- Started by Robin Fernandes on 2008-02-28T12:48:14+00:00
- Messages: 2
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #35847 — Robin Fernandes — 2008-02-28T12:48:14+00:00

URL: https://externals.io/message/35847#35847

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

---

## #35856 — Lokrain — 2008-02-28T16:26:40+00:00

URL: https://externals.io/message/35847#35856 · In reply to: #35847

Hello Robin,

This interesting issue, this should be patched asap!

Vote +1.

Best Regards, Dimitar Isusov
