Skip to content

extract() applied to an array with optional keys should not mark the corresponding extracted variables as potentially undefined #12364

@claudepache

Description

@claudepache

Bug report

Given:

/** @var array{y?: string} $a */
extract($a);

if variable $y is defined before the call to extract(), then $y is still defined after the call to extract(). However, PHPStan incorrectly consider it as potentially undefined.

Possibly related issue: #10436

Code snippet that reproduces the problem

https://phpstan.org/r/6e4c870b-7be1-453c-8f72-d94ed9f6ec83

Expected output

No “variable.undefined” error at line 15

Did PHPStan help you today? Did it make you happy in any way?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions