Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Unexpected behavior when modifying a passed-by-reference variable in an immediately invoked anonymous function; caused by generalization of typesΒ #11561

@ruudk

Description

@ruudk

Bug report

When I immediately call an anonymous function that uses a passed-by-reference variable, and modify the variable, the type information for the variable in the scope gets corrupted.

For example, this works fine:
https://phpstan.org/r/cff926d5-dcf6-48b8-a72d-7c0bc35d1bde

But as soon as you modify the passed-by-referenced variable, the scope gets corrupted.

You can see that from the assertion above the modification. It already contains the change, that happens after the assertion.

Also the structure of the type changes.

Code snippet that reproduces the problem

https://phpstan.org/r/55207449-fbb3-434e-8871-f07a20514457

Expected output

See assertions in the output.

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

πŸ’™πŸ’™πŸ’™πŸ’™πŸ’™πŸ’™πŸ’™πŸ’™πŸ’™

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions