New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
\settype() is not handled properly #3250
Labels
Milestone
Comments
This is a matter of writing a TypeSpecifyingExtension: https://phpstan.org/developing-extensions/type-specifying-extensions PHPStan already contains plenty of those. Feel free to send a PR :) |
@kiler129 PHPStan now reports different result with your code snippet: @@ @@
+PHP 7.4 – 8.0 (1 error)
+==========
+
+6: Function castTo() has no return typehint specified.
+
+PHP 7.3 (3 errors)
+==========
+
6: Function castTo() never returns float so it can be removed from the return typehint.
6: Function castTo() never returns int so it can be removed from the return typehint.
-6: Function castTo() never returns null so it can be removed from the return typehint.
+6: Function castTo() never returns null so it can be removed from the return typehint.
+
+PHP 7.1 – 7.2 (1 error)
+==========
+
+6: Function castTo() has no return typehint specified. Full reportPHP 7.4 – 8.0 (1 error)
PHP 7.3 (3 errors)
PHP 7.1 – 7.2 (1 error)
|
@kiler129 After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-6: Function castTo() never returns float so it can be removed from the return typehint.
-6: Function castTo() never returns int so it can be removed from the return typehint.
-6: Function castTo() never returns null so it can be removed from the return typehint.
+6: Function castTo() never returns float so it can be removed from the return type.
+6: Function castTo() never returns int so it can be removed from the return type.
+6: Function castTo() never returns null so it can be removed from the return type. Full report
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
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 */
The text was updated successfully, but these errors were encountered: