We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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 falsely reports string|null type although proper null check is done in ternary.
string|null
null
https://phpstan.org/r/3962507d-a02a-447b-9b46-23e08110b40b
<?php declare(strict_types = 1); function createFromString(string $timespec): DateTime { try { return new DateTime($timespec, new DateTimeZone('UTC')); } catch (Exception) { throw new InvalidArgumentException(sprintf('Invalid timespec "%s"', $timespec)); } } $rows = [ ['timespec'=>null], ['timespec'=>'2020-01-01T01:02:03+08:00'], ]; $result = []; foreach($rows as $row) { $result[] = ($row['timespec'] ?? null) !== null ? createFromString($row['timespec']) : null; }
No error.
Parameter #1 $timespec of function createFromString expects string, string|null given
Phpstan helps me every day, and the speed in which issues are fixed is absolutely amazing!
The text was updated successfully, but these errors were encountered:
Thank you for your kind words! 😊
/cc @rvanvelzen This looks like something that should have been fixed by your recent PR but wasn't.
Sorry, something went wrong.
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.
Successfully merging a pull request may close this issue.
Bug report
phpstan falsely reports
string|null
type although propernull
check is done in ternary.Code snippet that reproduces the problem
https://phpstan.org/r/3962507d-a02a-447b-9b46-23e08110b40b
Expected output
No error.
Acutal output
Parameter #1 $timespec of function createFromString expects string, string|null given
Did PHPStan help you today? Did it make you happy in any way?
Phpstan helps me every day, and the speed in which issues are fixed is absolutely amazing!
The text was updated successfully, but these errors were encountered: