bmewburn / vscode-intelephense

PHP intellisense for Visual Studio Code
https://intelephense.com
Other
1.56k stars 92 forks source link

Doesn't know the type when iterate iterable #2890

Open momala454 opened 1 month ago

momala454 commented 1 month ago

Describe the bug When doing foreach on iterables built in php, intelepehense doesn't know the type. Example DOMNodeList iterates to DOMElement|DOMNode|DOMNameSpaceNode|null

To Reproduce

$dom = new \DOMDocument();
            $xpath = new \DOMXPath($dom);

            $links = $xpath->query('.//a[@href]');
            assert($links !== false);
            foreach ($links as $link) {
                var_dump($link);
                exit;
            }

Expected behavior $link is DOMElement|DOMNode|DOMNameSpaceNode|null

Screenshots image

Platform and version OS and Intelephense version.

bmewburn commented 1 month ago

I think the upstream stubs could be improved to solve this https://github.com/JetBrains/phpstorm-stubs/blob/master/dom/dom_c.php#L1340