[php-src] Issue #15591: DOMNodeList and DOMNamedNodeMap already (partially) implement ArrayAccess
| From: | jnvsor | Date: | Mon, 26 Aug 2024 18:41:25 +0000 |
| Subject: | [php-src] Issue #15591: DOMNodeList and DOMNamedNodeMap already (partially) implement ArrayAccess | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-247599@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/15591
Author: jnvsor
### Description
```php
<?php
$xml = <<<END
<?xml version="1.0" encoding="UTF-8"?>
<root>
<child attribute="value" />
<child hello="world" />
</root>
END;
$doc = new DOMDocument();
$doc->loadXML($xml);
assert($doc->firstChild->childNodes[3]->attributes['hello'] ===
$doc->firstChild->childNodes->item(3)->attributes->getNamedItem('hello'));
assert($doc->firstChild->childNodes[3]->attributes['hello']->nodeValue ===
'world');
```
There doesn't seem to be any documentation indicating that
DOMNodeList,
DOMNamedNodeMap, and their php 8.4 Dom alternatives can be accessed like
an array.
According to https://3v4l.org/AGvek this has been the case
since 5.6.3, but it isn't even documented in the 5.6.3 changelog
The actual ArrayAccess interface isn't implemented on them because they don't
have the methods, but it would be nice to see it in the documentation even if it means implementing
them.
### PHP Version
8.3.9
### Operating System
_No response_