Skip to content

Destructuring assignment from null does not raise warning #3640

Open
@tgr

Description

@tgr

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugDocumentation contains incorrect information

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions