Phpstan: false positive on "if not instanceof"

Created on 11 Jan 2017  路  3Comments  路  Source: phpstan/phpstan

I have the following edge case:

function appendToRouter(IRouter $router)
{
    if ( ! $router instanceof RouteList || $router->getModule() !== NULL) {}
}

results in Call to an undefined method Nette\Application\IRouter::getModule(). which is a false positive because it is safe to assume that $router is an instance of RouteList in the right operand of the or.

Most helpful comment

Fixed the is_null case in: https://github.com/phpstan/phpstan/commit/3443da1c399610c5e3a50318bb10ffad5b1fbee0

Thanks for the reports @jiripudil and @CZechBoY!

All 3 comments

I think my issue is related to this issue (lazy eval of OR):
if (is_null($this->abc) || $abc !== $this->abc->property) { //... }
which results into

Cannot access property $property on null.

Fixed the is_null case in: https://github.com/phpstan/phpstan/commit/3443da1c399610c5e3a50318bb10ffad5b1fbee0

Thanks for the reports @jiripudil and @CZechBoY!

Was this page helpful?
0 / 5 - 0 ratings