Req #67949 [Com]: DOMNodeList should implement ArrayAccess
Edit report at https://bugs.php.net/bug.php?id=67949&edit=1
ID: 67949
Comment by: fmargaine@php.net
Reported by: daverandom@php.net
Summary: DOMNodeList should implement ArrayAccess
Status: Assigned
Type: Feature/Change Request
Package: DOM XML related
Operating System: Any
PHP Version: Irrelevant
Assigned To: fmargaine
Block user comment: N
Private report: N
New Comment:
PHP-5.6: https://github.com/php/php-src/commit/9469db93110b2185f019da0dd66d3537c1a4b7a4
master PR (https://github.com/php/php-src/pull/842) still pending, but shouldn't have any issue
since the 5.6 PR was merged.
Previous Comments:
------------------------------------------------------------------------
[2014-09-02 13:21:37] daverandom@php.net
Description:
------------
DOMNodeList should implement ArrayAccess. The write methods should either silently fail or throw a
DOMException (probably the latter).
It would probably also be an idea to implement Countable at the same time, allowing for better
interop between node lists and arrays of nodes.
Test script:
---------------
<?php
$html = <<<HTML
<div>data</div>
HTML;
$doc = new DOMDocument;
$doc->loadHTML($html);
var_dump($doc->getElementsByTagName('div')[0]->textContent);
Expected result:
----------------
string(4) "data"
Actual result:
--------------
Fatal error: Cannot use object of type DOMNodeList as array in...
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=67949&edit=1
Thread (3 messages)