Skip to content

false positive with array_key_exists and cast to array #3821

@keksa

Description

@keksa

Bug report

Code snippet that reproduces the problem

<?php declare(strict_types = 1);

abstract class AbstractMap {}

class HelloWorld
{
    public function fieldExists(AbstractMap $map, string $mapFieldName): bool
    {
        return array_key_exists($mapFieldName, (array) $map);
    }
}

https://phpstan.org/r/74a191d3-489d-430c-adcc-2be1bd1775da

Call to function array_key_exists() with string and array() will always evaluate to false.

Expected output

no issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions