On 25-01-2022 00:47, Mark Randall wrote:
Internals,
PHP 9.0, likely a few years away at this point, is our next opportunity
to make significant breaking changes.
So I thought it would be appropriate to start a thread discussing what
breaking changes we might want to include in it, specifically in
relation to error handling behaviour both at engine level, and
potentially library level.
Recently I came across the following array destructuring edge case:
[$a, $b] = 1;
This statement is perfectly valid. No exception, no error, no notice,
nothing. Its effect is that it assigns null to both variables. IMHO the
above should be a compile time error.
Also, I think the following should throw a TypeError when the right hand
side is not iterable:
[$a, $b] = $c;
Currently, the above statement silently assigns null to both $a and $b.
In the context of a foreach loop, the behavior is slightly better. The
following generates a warning:
foreach (1 as [$b, $c]);
As does the following if $a is not iterable:
foreach ($a as [$b, $c]);
As array destructuring is conceptually related to array unpacking I
would expect the engine to handle similar cases in the same way. This is
not the case though. The following statement throws a TypeError since
PHP 8.0:
var_dump(...1);
And, while we are at it, the following is a fatal error:
$a = [...1];
while the following throws an Error exception (should be TypeError?)
when $b is not iterable:
$a = [...$b];
Perhaps these oddities / inconsistencies are good candidates for
addressing in PHP 9.0?
Regards,
Dik Takken
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php