-
-
Notifications
You must be signed in to change notification settings - Fork 864
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
php8's match: result of void is used #4292
Comments
I just fixed a similar bug today, feel free to send a PR with a fix for this one :) phpstan/phpstan-src@7ac6383 |
I just run into this issue. I would be careful about this one though. This seems like an undefined behaviour to me. It is not discussed in the official docs, it is not discussed in the RFC. For example, PHPStorm will report the same issue as PHPStan does. The closest mention in the docs related to the issue is "A match expression returns a value" and "The result of a match expression does not need to be used". If we were to strictly adhere to this, the fact that the code above works is a bug in PHP. |
I have filed a bug report https://bugs.php.net/bug.php?id=80858. I denoted it as a documentation bug for now, as the inteded behavior is not clear to me. |
It's not a PHP bug. In runtime void function actually returns null so handling the value is consistent with the rest of the language. |
I tried with psalm https://psalm.dev/r/f7b57538bf and gives no error. How will phpstan approach this in the future? Is it safe to ignore error for now? |
Ondrej wrote that this is considered bug and should be fixed. ref However I'm currently too busy to prepare PR. Feel free to prepare it, I will be happy to do pre-review or initial consulation. |
Fixed: phpstan/phpstan-src@90e49f7 |
Thank you @ondrejmirtes ! |
FYI instead I wrote this rule: phpstan/phpstan-src@2c0dda3 |
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. |
Bug report
Even when result of match() is not used, phpstan reports that arm of match that contains fn which returns void is invalid. https://3v4l.org/Tcge3 (no error)
Code snippet that reproduces the problem
https://phpstan.org/r/aae87ebf-09e9-4bd1-a13b-2a39ff9af6f3
Expected output
PHPStan should ignore cases when match() result is not used, no matter what inner function returns.
The text was updated successfully, but these errors were encountered: