Skip to content

Numeric string array keys with isset/assertArrayHasKey causing false positive error #6163

@Tobion

Description

@Tobion

Bug report

Numeric string array keys are treated as they cannot exist in arrays with string keys.
We have an array with product ids which can be numeric but do not need to be.

When we then assert that the product array key exists phpstan raises a false positive error.

$this->assertArrayHasKey('123000000000', $products);

Call to method PHPUnit\Framework\Assert::assertArrayHasKey() with '123000000000' and array<string ...> will always evaluate to false.

Code snippet that reproduces the problem

https://phpstan.org/r/1f3ae39c-9789-4bff-802c-a68b86c5cfce

This is using isset instead of assertArrayHasKey but it's showing the same source problem I assume.

Expected output

No error detected

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

Thanks for the tool!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions