Closed
Description
Bug report
The result of incrementing a string is not necessarily a string.
function inc(string $n): string
{
$before = $n;
$after = ++$n;
assertType('array{string|int, string, string|int}', [$n, $before, $after]));
return (string)$after; // No warnings expected here
}
inc('10'); // => '11'
inc('a'); // => 'b'
This behavior is consistent between PHP 8.3 and earlier: https://3v4l.org/i4rru
There seems to be a problem with InitializerExprTypeResolver::getPlusType()
.
Code snippet that reproduces the problem
https://phpstan.org/r/110b3926-f4c5-4f51-b4ab-537fa2be3fb6
Expected output
No errors.
Did PHPStan help you today? Did it make you happy in any way?
I'm excited to see that PHPStan is working consistently even with PHP 8.3.