# [VOTE] Make compact function reports undefined passed variables

- Thread: https://externals.io/message/102243
- Original archive: https://news-web.php.net/php.internals/102243
- Started by Dmitry Stogov on 2018-06-13T08:42:16+00:00
- Messages: 1
- 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

---

## #102243 — Dmitry Stogov — 2018-06-13T08:42:16+00:00

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

>The existence of anything that internally relies on `get_defined_vars()` is a
>blocker for applying further optimisations to the engine (think stack frames),
>which is probably why Dmitry suggested its removal.

I did not know it was an optimization issue.

Accessing variables by name is a problem for optimimisation and JIT-ing, because we lose data-flow dependencies. But, this is not the end of the world. We just don't optimize functions that use this "bad" pattern.

Thanks. Dmitry.




I suppose I could substitute a userland equivalent:

function compact_(array $compact, array $vars)
{
    return array_intersect_key($vars, array_flip($compact));
}

which changes A::c() to

function c()
{
    $d = $this->d();
    $a = pow($d, $d + 1);
    $c = $a ^ 0b1100;
    $b = $a - $d;

    return new B(
        compact_(
            $this->b(),
            `get_defined_vars()`
        )
    );
}

That is not so bad. As far as I am concerned, deprecate away.
