-
-
Notifications
You must be signed in to change notification settings - Fork 946
Open
Labels
Milestone
Description
Bug report
PHPStan seems to be blind to typecasts done via \settype() and suggests that variable type didn't change.
Code snippet that reproduces the problem
<?php declare(strict_types = 1);
/**
* @return string|int|float|null Based on the specified casting
*/
function castTo(string $value, string $castTo)
{
$newValue = $value;
settype($newValue, $castTo);
return $newValue;
}https://phpstan.org/r/20eca26c-c9a6-458e-ab03-23cf27cd57eb
Expected output
I think if type cannot be inferred (like in the example above) the return type should be simply trusted. Additional think which will be even better is suggesting the user to add declaration before settype(), e.g.: /** @var string|int|float|bool|null $newValue */
Reactions are currently unavailable