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

Throw in short closure false-positive #7890

Closed
enumag opened this issue Sep 1, 2022 · 7 comments
Closed

Throw in short closure false-positive #7890

enumag opened this issue Sep 1, 2022 · 7 comments
Labels
Milestone

Comments

@enumag
Copy link
Contributor

enumag commented Sep 1, 2022

https://phpstan.org/r/32d2c030-666b-4e37-94bf-2f82ca9ce28f

Considering that throw is now an expression I think this should be considered valid. Code works perfectly fine in newer versions of PHP.

@rvanvelzen
Copy link
Contributor

Why would you write this?

@enumag
Copy link
Contributor Author

enumag commented Sep 1, 2022

A callback that needs to exist because of architecture but throws an IntentionallyNotImplementedException because it should never be executed.

@ondrejmirtes
Copy link
Member

Interesting fact: never doesn't work here https://3v4l.org/XuG9Q and it's been fixed on PHP 8.2: php/php-src#7900

@ondrejmirtes ondrejmirtes added this to the Easy fixes milestone Sep 1, 2022
@phpstan-bot
Copy link
Contributor

@enumag After the latest push in 1.11.x, PHPStan now reports different result with your code snippet:

@@ @@
-PHP 8.0 – 8.2 (1 error)
+PHP 8.0 – 8.2
 ==========
 
-3: Anonymous function should never return but return statement found.
+No errors
 
-PHP 7.4 (2 errors)
+PHP 7.4 (1 error)
 ==========
 
-3: Anonymous function should never return but return statement found.
 3: Throw expression is supported only on PHP 8.0 and later.
 
 PHP 7.1 – 7.3 (2 errors)
Full report

PHP 8.0 – 8.2

No errors

PHP 7.4 (1 error)

Line Error
3 Throw expression is supported only on PHP 8.0 and later.

PHP 7.1 – 7.3 (2 errors)

Line Error
3 Syntax error, unexpected ':' on line 3
3 Syntax error, unexpected T_STRING, expecting T_PAAMAYIM_NEKUDOTAYIM on line 3

@ondrejmirtes
Copy link
Member

Fixed: phpstan/phpstan-src@758e5f1

@enumag
Copy link
Contributor Author

enumag commented Nov 28, 2023

ty!

Copy link

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 Dec 30, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants