Bug report
After upgrading from 2.1.27 to 2.1.28, PHPStan started to report strange false positives on my projects. Apparently, when comparing the result of a trim($value) operation, the $value variable is narrowed to a string.
function doSomething(mixed $value): void
{
if (trim($value) === '') {
return;
}
\PHPStan\dumpType($value);
}
Here, PHPStan believes that $value must be a non-empty-string which I believe is wrong. $value could be anything that can be cast to a string, such as an integer or a Stringable object.
Code snippet that reproduces the problem
https://phpstan.org/r/8cbb0de1-d0c3-4c13-bcf5-7cbd1b1fd69a
Expected output
$value should still be mixed.
Did PHPStan help you today? Did it make you happy in any way?
No response
Bug report
After upgrading from 2.1.27 to 2.1.28, PHPStan started to report strange false positives on my projects. Apparently, when comparing the result of a
trim($value)operation, the$valuevariable is narrowed to a string.Here, PHPStan believes that
$valuemust be anon-empty-stringwhich I believe is wrong.$valuecould be anything that can be cast to a string, such as an integer or aStringableobject.Code snippet that reproduces the problem
https://phpstan.org/r/8cbb0de1-d0c3-4c13-bcf5-7cbd1b1fd69a
Expected output
$valueshould still bemixed.Did PHPStan help you today? Did it make you happy in any way?
No response