Skip to content
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

unsupported php types in lower php versions not detected #5629

Closed
Tobion opened this issue Sep 14, 2021 · 3 comments
Closed

unsupported php types in lower php versions not detected #5629

Tobion opened this issue Sep 14, 2021 · 3 comments

Comments

@Tobion
Copy link

Tobion commented Sep 14, 2021

Bug report

We used a mixed type declarations on a parameter which is only available since PHP 8.
Testing this code with the highest phpstan level and running on PHP 7.4 did not report this as error.
But it should IMO as PHP 7.4 treated the mixed type as a class name which does not exist in the current namespace.

Code snippet that reproduces the problem

https://phpstan.org/r/6c15ac7b-d3c3-4d30-8df6-268c30ac4666

Expected output

Testing this with PHP 7.4 should show an error that mixed does not exist/is not available.

Did PHPStan help you today? Did it make you happy in any way?

Wasn't helpful today but certainly on other days ;)

@thomasheller
Copy link

The same applies when using mixed return type with PHP 7.4:

https://phpstan.org/r/f8ca673d-a5d8-4337-9269-23439ccb17fa

This error is also not detected.

@ondrejmirtes
Copy link
Member

This will be solved in PHPStan 2.0 being released at some point in 2024, thanks to upgrade to nikic/php-parser 5.0. From the upgrade guide:

Type hints are interpreted as a class Name or as a built-in Identifier depending on PHP version, for example int is treated as a class name on PHP 5.6 and as a built-in on PHP 7.0.

Work in progress: phpstan/phpstan-src#2839

Result diffs of your code snippets:

@@ @@
-No errors
+PHP 8.0
+==========
+
+No errors
+
+PHP 7.1 – 7.4 (1 error)
+==========
+
+5: Parameter $param of method HelloWorld::test() has invalid type mixed.
@@ @@
-No errors
+PHP 8.0
+==========
+
+No errors
+
+PHP 7.1 – 7.4 (3 errors)
+==========
+
+5: Method HelloWorld::test() has invalid return type mixed.
+5: Parameter $param of method HelloWorld::test() has invalid type mixed.
+7: Method HelloWorld::test() should return mixed but returns string.

Copy link

github-actions bot commented Feb 2, 2024

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants