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

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy