Skip to content

Closure / Arrow functions type difference when an array is reset #13563

@clement-michelet

Description

@clement-michelet

Bug report

Rector migrated our codebase and converted some closure to arrow functions.
PHPStan started to complain about invalid nullCoalesce usage.

When an array is reset (i.e. $var = []), the type will go back to array{}.
PHPStan seems to resolve the type to the original one when using a closure and the same as the parent scope when using an arrow function.

Sandbox with dumpedTypes : https://phpstan.org/r/99598551-bf43-46bb-acd5-57b104567c62

Code snippet that reproduces the problem

https://phpstan.org/r/a109bac9-6415-454e-a302-924c4a4c39e4

Expected output

Either the closure should complain as the arrow function or the arrow function should resolve the same type as the closure

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

It save my life while doing big refactoring ❤️

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions