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
PHPStan incorrectly states BCMath functions can return null in PHP 8 project #5134
Comments
This bug report is missing a link to reproduction on phpstan.org. It will most likely be closed after manual review. |
Updated with link to reproduce. |
This extension needs to be fixed: https://github.com/phpstan/phpstan-src/blob/master/src/Type/Php/BcMathStringOrNullReturnTypeExtension.php |
I'm working on a pull request, however there are a few test cases present in the test file ( What is the preferred way to make an exception for these cases? |
It should be tested in NodeScopeResolverTest. You can yield from different files based on PHP_VERSION_ID. |
@khkramer After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-10: Function divide() should return string but returns string|null.
+ 6: Function divide() should return string but return statement is missing. Full report
|
Fixed by phpstan/phpstan-src#1152 |
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
In a PHP 8 only codebase PHPStan currently states:
Function divide() should return string but returns string|null.
It only seems to happen when strict typing is declared in the php file.
While PHP 8 bcmul and bcdiv either return a numeric string or throw an exception when dividing by zero. ( According to the Jetbrains stubs and which I have verified )
Code snippet that reproduces the problem
https://phpstan.org/r/376c482f-e055-400f-b8f5-d212d2ca1b9d
Expected output
I would have expected it to not have emitted an error in this instance.
I have also looked at the phpstan-src repository and I saw that the correct return types are present in one of the delta files, but I can't figure out why they aren't used in my instance.
Did PHPStan help you today? Did it make you happy in any way?
In general I'm very happy with PHPStan providing some stability in the unsafe world that is PHP :)
The text was updated successfully, but these errors were encountered: