Re: What is the prevailing sentiment about extract() and compact() ?
| From: | David Gebler | Date: | Wed, 29 Nov 2023 20:17:06 +0000 |
| Subject: | Re: What is the prevailing sentiment about extract() and compact() ? | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-121863@lists.php.net to get a copy of this message | ||
On Wed, Nov 29, 2023 at 7:19 AM Stephen Reay <php-lists@koalephant.com>
wrote:
> So no, I don't think compact() should be deprecated, what I think *should*
> happen, is to promote the current warning on undefined variables, to an
> error, as per https://wiki.php.net/rfc/undefined_variable_error_promotion..
>
> Whether this is a foregone conclusion or not, I don't know because that RFC
> doesn't mention compact() specifically.
>
>
I remember fixing a bug in compact where passing parameters which were not
array or string were silently accepted - something I discovered when I was
tracking down a bug in my code once and it turned out I'd accidentally done
compact($x) instead of compact('x') - and that now gives a warning,
consistent with the warning when variable names given are undefined.
I don't want to see either compact or extract deprecated because I do use
both (as do countless open source systems) and I don't think there is a
reasonable justification for deprecating them. The behaviour of these
functions is understood by static analysis tools, the alternatives are more
verbose and more prone to developer error / mistakes from typos. I do agree
with upping the error level in compact() from E_WARNING to E_ERROR and
upping the warning on bad parameter types to a TypeError (which is what I'd
originally pushed for), but I think these things should be a change to
compact specifically, separate from any other RFC.
-Dave