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

DOMNamedNodeMap, Dom\NamedNodeMap, DOMNodeList, Dom\NodeList, Dom\HTMLCollection, and Dom\DtdNamedNodeMap raises UndefinedMethod - 5:16 - Method DOMNamedNodeMap::offsetGet does not exist #11187

Open
Girgias opened this issue Dec 17, 2024 · 3 comments

Comments

@Girgias
Copy link

Girgias commented Dec 17, 2024

Similar to phpstan/phpstan#12235.

Some internal classes do not implement ArrayAccess but allow accessing offsets regardless.

This would be fixed on the PHP side with https://wiki.php.net/rfc/container-offset-behaviour

Copy link

Hey @Girgias, can you reproduce the issue on https://psalm.dev? These will be used as phpunit tests when implementing the feature or fixing this bug.

@Girgias
Copy link
Author

Girgias commented Dec 17, 2024

Psalm snippet: https://psalm.dev/r/f52aab0ba2

Copy link

I found these snippets:

https://psalm.dev/r/f52aab0ba2
<?php

function takesAnInt(DOMElement $e): ?DOMAttr {
    if ($e->hasAttributes()) {
        return $e->attributes[0];
    }
    return null;
}
Psalm output (using commit 765dcbf):

ERROR: UndefinedMethod - 5:16 - Method DOMNamedNodeMap::offsetGet does not exist

INFO: MixedReturnStatement - 5:16 - Could not infer a return type

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

No branches or pull requests

1 participant