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

PHPStan insists a use variable by reference cannot change types  #7751

Description

@neildaniels

Bug report

When writing a Closure with a use reference variable, PHPStan assumes the Type of that variable is always what it was at the place where the code is written.

Code snippet that reproduces the problem

$foo = false;

$test = function() use (&$foo) {
	if (is_array($foo)) {
		echo 'array';
	}
	else {
		echo 'not array';	
	}
};

$foo = [];

$test();

The code above actually prints array, even though PHPStan insists that:

Call to function is_array() with false will always evaluate to false.

https://phpstan.org/r/6967bdde-8c8f-476d-adcd-c94db723cd8b

Expected output

No reported error.

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

Yes! Love having a another pair of eyes on my code!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions