-
-
Notifications
You must be signed in to change notification settings - Fork 897
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 Cannot access offset
error
#12235
Comments
It'd be enough to add the missing classes to this list https://github.com/phpstan/phpstan-src/blob/36656357396bb2a5dadaafbd69e611be8e73f660/src/Type/ObjectType.php#L64. If the offsets cannot be set in some of them, we'd have to write some extra code in |
Wouldn't it be better to add a parameter to enum OffsetAccessType {
case Read; // Include existence checks
case Write;
case Unset;
case Append;
case Fetch; // This one would be for references, but possibly delay it?
} And then overload |
@Girgias After the latest push in 2.0.x, PHPStan now reports different result with your code snippet: @@ @@
==========
7: Cannot access offset 'role' on Dom\NamedNodeMap.
-14: Cannot access offset 'role' on DOMNamedNodeMap.
+14: Cannot access offset 'role' on DOMNamedNodeMap&iterable<DOMAttr>.
PHP 7.2 – 8.3 (4 errors)
==========
@@ @@
5: Parameter $element of method HelloWorld::foo1() has invalid type DOM\Element.
7: Access to property $attributes on an unknown class DOM\Element.
7: Cannot access offset 'role' on mixed.
-14: Cannot access offset 'role' on DOMNamedNodeMap.
+14: Cannot access offset 'role' on DOMNamedNodeMap&iterable<DOMAttr>. Full reportPHP 8.4 (2 errors)
PHP 7.2 – 8.3 (4 errors)
|
Fixed phpstan/phpstan-src#3725 |
Bug report
This could also be considered a feature request.
All these classes can read and check the existence of an index via array notation.
One possible way I can see to fix this in the stubs is to have it implement
ArrayAccess
and have a return type ofnever
foroffsetSet()
andoffsetUnset()
, but it does not have the other two offset methods either.This would be fixed on the PHP side with https://wiki.php.net/rfc/container-offset-behaviour
Code snippet that reproduces the problem
https://phpstan.org/r/3b7685e4-3ad7-4eed-92a1-e85c88fa22cb
Expected output
No errors.
Did PHPStan help you today? Did it make you happy in any way?
No response
The text was updated successfully, but these errors were encountered: