🌐 US-Proxy
class="logged-out env-production page-responsive" style="word-wrap: break-word;" >
Skip to content

Incorrect type inferred from array destructuring #7155

Description

@devfrey

Bug report

I'm sorry for the lack of a more specific title. I don't know how else to describe this issue.

PHPStan is unable to correctly infer the type from the following array destructure:

/** @var \Closure|string $event */
$event = '';
$callback = null;

if ($event instanceof \Closure) {
    [$event, $callback] = ['event-name', $event];
}

// $callback should be Closure|null, but is reported as 'event-name'|null

This example is based on this real-world code.

Code snippet that reproduces the problem

https://phpstan.org/r/f75d63a2-9a54-46ee-8f89-ecf6de70c5a9

Expected output

PHPStan should infer $callback as \Closure|null.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions