doc-en icon indicating copy to clipboard operation
doc-en copied to clipboard

Destructuring assignment from null does not raise warning

Open tgr opened this issue 1 year ago • 1 comments

https://www.php.net/manual/en/language.types.array.php#language.types.array.syntax.destructuring says

Attempting to access an array key which has not been defined is the same as accessing any other undefined variable: an E_WARNING-level error message (E_NOTICE-level prior to PHP 8.0.0) will be issued, and the result will be null.

but this isn't actually true when assigning null; [$x, $y] = null; does not raise a notice or warning (eval). Same goes for destructuring with an associative array (eval). This seems to be specific to null (e.g. [$x, $y] = []; raises a warning: eval) and to destructuring assignment (e.g. null[0] raises a warning: eval).

Not sure if this is a bug or a documentation issue, but either there should be a warning or this special case should be documented.

tgr avatar Aug 05 '24 19:08 tgr

Well, let's say it's a feature, but document it (also for list()).

cmb69 avatar Aug 07 '24 19:08 cmb69

@Girgias Given this is now deprecated, feel free to close when it has been documented.

iluuu1994 avatar Aug 21 '25 15:08 iluuu1994