Unable to infer type when modifying an array
Summary of a problem or a feature request
PHPStan is unable to infer the type of an array's values after it has been modified. I suspect this might be a difficult case to solve.
Code snippet that reproduces the problem
Both a foreach by reference and an ordinary for loop report an error.
https://phpstan.org/r/da003dee5a95afa552994b8f36ac3512 (foreach by reference)
https://phpstan.org/r/1179579fc016f23eff3768d5b5886ae2 (for loop)
Using array_map() doesn't report an error.
https://phpstan.org/r/6f6886451efa8231aa7d24d5789aa2d5
Expected output
PHPStan should not emit an error when the array is modified to contain the correct value type.