Skip to content
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

Analyse constant xpath expression #9553

Open
mvorisek opened this issue Jul 1, 2023 · 1 comment
Open

Analyse constant xpath expression #9553

mvorisek opened this issue Jul 1, 2023 · 1 comment

Comments

@mvorisek
Copy link
Contributor

mvorisek commented Jul 1, 2023

Feature request

Like https://phpstan.org/r/9c6ac5fc-d975-473e-ab7c-dc95ece0c6b1 (issue #2046) - DOMDocument::getElementsByTagName() always return collection of DOMElement.

#7681 is valid issue, xpath expression in the repro below always returns collection of DOMElements.

This is a feature request to analyse constant string xpath input to narrow the return type based on it. Per [1] the result is also never false as long as the expression is valid.

repro https://phpstan.org/r/6f02c158-3f87-4c04-b4d5-0dd5ee322ce7

functional repro: https://3v4l.org/l2B9Hq/rfc#vgit.master

[1] https://www.php.net/manual/en/domxpath.query.php#refsect1-domxpath.query-returnvalues

@mvorisek mvorisek changed the title Analyse xpath expression to determine if the result is collection of DOM elements Analyse constant xpath expression Jul 1, 2023
@phpstan-bot
Copy link
Contributor

@mvorisek After the latest push in 1.11.x, PHPStan now reports different result with your code snippet:

@@ @@
-20: Cannot call method getAttribute() on DOMNode|null.
+ 7: Property Foo::$content is never written, only read.
+ 9: Method Foo::doFoo() has no return type specified.
Full report
Line Error
7 Property Foo::$content is never written, only read.
9 Method Foo::doFoo() has no return type specified.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants