Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If condition is always true (pass by reference to a callable) #5615

Closed
someonewithpc opened this issue Sep 11, 2021 · 2 comments
Closed

If condition is always true (pass by reference to a callable) #5615

someonewithpc opened this issue Sep 11, 2021 · 2 comments

Comments

@someonewithpc
Copy link

someonewithpc commented Sep 11, 2021

Bug report

/**
 * @param callable(bool &$save): void $call
 */
function get(callable $call) {
    $save = true;
    $call($save);
    if ($save) {
        echo "Save item\n";
    } else {
        echo "Don't save\n";
    }
}

get(function (bool &$save) {}); // Save item
get(function (bool &$save) { $save = false; }); // Don't save

Code snippet that reproduces the problem

https://phpstan.org/r/528c3596-7697-4fe6-810d-3ce01231328c

Expected output

If condition is always true.

This error is a false positive, since the callable takes the bool by reference and might, thus, modify it

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

It's been very helpful, found a bunch of real bugs and improvements :)

@ondrejmirtes
Copy link
Member

Thank you for your kind words! :)

Fixed: phpstan/phpstan-src@109bf99

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants