Description
Hi,
Recently I've been working on a tool that I was using internally to generate random typed values.
I pushed it online 3 days ago so I can use it everywhere easily, find the tool here: https://github.com/loophp/typed-generators
I noticed an issue while working on the ArrayType and I'm opening this issue to know if this issue is legit.
I reproduced the issue on the PHPStan playground here: https://phpstan.org/r/518a80cb-3a3d-460a-8bc5-e0791d732063
Sorry for the size of the snippet, while writing this issue I'm still looking for a reproducer with smaller amount of code.
I added some comments in the snippet to show you were PHPStan fails to infer the proper type.
IMHO, I think there is a bug somewhere because when changing the type definition from ArrayType<TKey|VKey, T|V> to ArrayType<VKey|TKey, T|V> (line 118), the PHPStan output is different.
The same snippet in PSalm is behaving correctly: https://psalm.dev/r/b48de03f7e
Activity
rvanvelzen commentedon Jun 9, 2022
Using
int|stringinstead ofarray-keymight help herephpstan-bot commentedon Jan 13, 2023
@drupol After the latest push in 1.10.x, PHPStan now reports different result with your code snippet:
Full report
PHP 8.0 – 8.1 (4 errors)
PHP 7.1 – 7.4 (5 errors)
phpstan-bot commentedon Jan 14, 2023
@drupol After the latest push in 1.10.x, PHPStan now reports different result with your code snippet:
Full report
PHP 8.0 – 8.1 (2 errors)
PHP 7.1 – 7.4 (3 errors)
phpstan-bot commentedon Feb 25, 2023
@drupol After the latest push in 1.10.x, PHPStan now reports different result with your code snippet:
Full report
PHP 8.0 – 8.1 (3 errors)
PHP 7.1 – 7.4 (4 errors)
phpstan-bot commentedon Oct 25, 2025
@drupol After the latest push in 2.1.x, PHPStan now reports different result with your code snippet:
Full report
PHP 8.0 – 8.1 (3 errors)
PHP 7.1 – 7.4 (4 errors)
phpstan-bot commentedon Sep 9, 2026
Closed via merging phpstan/phpstan-src#6376
github-actions commentedon Oct 11, 2026
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.