Re: What is the prevailing sentiment about extract() and compact() ?
| From: | Marco Pivetta | Date: | Fri, 01 Dec 2023 12:33:18 +0000 |
| Subject: | Re: What is the prevailing sentiment about extract() and compact() ? | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-121896@lists.php.net to get a copy of this message | ||
Hey Juliette,
On Wed, 29 Nov 2023 at 03:00, Juliette Reinders Folmer <
php-internals_nospam@adviesenzo.nl> wrote:
>
> For now, I'm just wondering how people feel about these functions.
>
From my PoV: burn them with fire.
The translation of
compact() is **trivial** with a CS tool (like the one
you maintain), and the translation of extract($vars) is `foreach ($vars
as $k => $v) { $$k = $v; }`, and that's all there is.
Instead, both compact() and extract() come at additional cognitive load
when reading, scanning, analyzing, debugging and generally understanding
code: a flamethrower helps.
Meanwhile, I'm also wondering if the removal of such functions would help
more in future AOT and JIT improvements: I suppose code using extract()
and compact() would immediately defeat any JIT, or at least lead to added
code to handle them correctly?
There's a section describing this in HHVM, which is the kind of
problem-space I was thinking of:
https://hhvm.com/blog/713/hhvm-optimization-tips
Marco Pivetta
https://mastodon.social/@ocramius
https://ocramius.github.io/