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
SimpleXmlElement weirdness #2784
Comments
@ondrejmirtes you added Easy Fixes on this. Any indication how to proceed? I will try to propose the PR |
Relevant code: https://github.com/phpstan/phpstan-src/blob/master/src/Type/Php/SimpleXMLElementClassPropertyReflectionExtension.php, https://github.com/phpstan/phpstan-src/blob/master/src/Reflection/Php/SimpleXMLElementProperty.php. You could do It's possible that BenevolentUnionType should override hasMethod, getMethod etc. methods so that level 8 does not complain about accessing something on possibly null type. It's completely valid use-case that people are sure about their XML structure and know some attribute isn't going to be null. |
Thanks! I will try to look at it with a clear head (so, not tomorrow night! Nor the day after!) soon. |
@orklah PHPStan now reports different result with your code snippet: @@ @@
+No errors
+
+PHP 7.3 – 7.4 (2 errors)
+==========
+
+6: Call to function assert() with true will always evaluate to true.
+6: Instanceof between SimpleXMLElement and SimpleXMLElement will always evaluate to true.
+
+No errors
+
+PHP 7.1 (2 errors)
+==========
+
6: Call to function assert() with true will always evaluate to true.
6: Instanceof between SimpleXMLElement and SimpleXMLElement will always evaluate to true. Full reportPHP 8.0No errors PHP 7.3 – 7.4 (2 errors)
PHP 7.2No errors PHP 7.1 (2 errors)
|
Oh this is weird, PHP 7.2 should not be different than 7.1, 7.3 and 7.4 here. Not sure about 8.0 though, something may have change internally. This issue could be fixed by merging phpstan/phpstan-src#76 however |
@orklah Sorry, there's some weird bug with the bot and the playground, I need to look into it. |
@orklah After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
+4: Class SimpleXMLElement referenced with incorrect case: SimpleXmlElement.
6: Call to function assert() with true will always evaluate to true.
+6: Class SimpleXMLElement referenced with incorrect case: SimpleXmlElement.
6: Instanceof between SimpleXMLElement and SimpleXMLElement will always evaluate to true. Full report
|
Fixed by: phpstan/phpstan-src#76 |
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
PHPStan thinks every direct call to an attribute on a SimpleXmlElement will return a SimpleXmlElement. This is not always true:
https://phpstan.org/r/f9336943-20db-4b3e-a9ba-671b6f58bd78
https://3v4l.org/kWSfE
While the first attribute does indeed return a SimpleXmlElement(even when the xml doesn't contain this element), this is not true for the second one.
PHPStan should not complain about always true checks in this context.
The text was updated successfully, but these errors were encountered: