Skip to content

Array index missing integer type #10596

@imhdCePo

Description

@imhdCePo

Bug report

Hello,

Following example does not return any error, which is incorrect:
https://phpstan.org/r/5beafa65-1be9-491c-9d90-8cff0171c40c

When using strict_types, page does not even load, due to the issue on line 16. An integer is passed as needle for mb_strpos(). However, removing comment from line 11 invokes error correctly.

The issue is present only when index of an array is from a returned function. Function itself defines that string is always returned. However, numeric string is internally transformed by PHP into integer.

To fix the problem, needle on line 16 should be cast to string. PHPStan complains about it incorrectly:
https://phpstan.org/r/988d7e56-c4b6-4a3d-8bfd-bc1a1f72f67e

Code snippet that reproduces the problem

https://phpstan.org/r/5beafa65-1be9-491c-9d90-8cff0171c40c

Expected output

Error is expected:

Parameter #2 $needle of function mb_strpos expects string, int|string given.

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

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions