-
-
Notifications
You must be signed in to change notification settings - Fork 947
Array index missing integer type #10596
Description
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