Skip to content

Inline assignment triggers "Call to function is_bool() with bool will always evaluate to false" #9666

@lkrms

Description

@lkrms

Bug report

Code snippet for reference:

<?php declare(strict_types=1);

class A
{
    /**
     * @return array<int,bool>
     */
    function b()
    {
        return [];
    }
}

$a = new A();
$b = $a->b();
$c = null;
if ($b && is_bool($c = reset($b))) {
    //
}

PHPStan doesn't report any errors if I remove the $c = , but assigning the result of reset($b) in the same statement triggers the incongruous error: "Call to function is_bool() with bool will always evaluate to false."

Code snippet that reproduces the problem

https://phpstan.org/r/9735203c-c32d-40fe-a564-5432e8e675db

Expected output

An error shouldn't be triggered by this code.

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

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions