-
-
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
Strict comparison for functions that return false on failure. #43
Comments
Unfortunately reflection data of internal PHP functions and methods are neglected and often out of sync. During development of PHPStan I encountered and reported three bugs: 70960, 71077, 71416 (was not able to convince the devs in the last case). Each one of them is "fixed" in PHPStan by a special condition. But your issue is weird. PHP does not report any return type for Let me know if we're on the right path. |
I've added further info on 71416 and re-opened it. |
Made the test I think we need to have a mechanism to easily add broken PHP reflection to PHPStan so that PHPStan can "just do it's job" and the devs don't need to jump through hoops to get PHPStan happy. |
It's still a mystery to me why PHPStan thought in your case that realpath returns boolean since PHP reflection does not report any return type. I suspect you have your own As for broken PHP reflection - I have a few PHP bugfixes in the codebase (look for |
I'm pretty positive we haven't our own implementation of realpath. REALLY positive! |
OK, so try to come up with a reproducing testcase of this issue. The only possible explanation I have for this is the one I described. |
Ha ha ha! The issue was that the type of the property declared in its docblock to which I had assigned the result of realpath() was just |
You should use |
Since PHP 7, false is internally a type. Boolean is a union of true and false. For example typescript considers false also as specific type. Supporting true and false as types allows better static analysis. It's also explicitly mentioned in phpDoc documentation. |
OK, shouldn't be a problem to add it. |
@JanTvrdik @hrach Implemented in 3f4435c. Thanks for the suggestion. |
For example:
Results in
Strict comparison using === between bool and string will always evaluate to false.
Whilst the statement about the comparison is true,
realpath()
returnsfalse
for a non existent file.I suspect
realpath(string $path): ?string
would solve this issue.Which is PHP7.1. Not sure how many of the functions and methods in core/extensions have been updated to reflect this. Hopefully all of them!!
The text was updated successfully, but these errors were encountered: