# Request #67949 DOMNodeList should implement ArrayAccess

- Thread: https://externals.io/message/77413
- Original archive: https://news-web.php.net/php.internals/77413
- Started by Florian Margaine on 2014-09-21T11:39:14+00:00
- Messages: 3
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #77413 — Florian Margaine — 2014-09-21T11:39:14+00:00

URL: https://externals.io/message/77413#77413

Hi list,

The request is so that we can do this:

$html = <<<HTML
<div>data</div>
HTML;
$doc = new DOMDocument;
$doc->loadHTML($html);
var_dump($doc->getElementsByTagName('div')[0]->textContent);

I started implementing this on my branch (
https://github.com/Ralt/php-src/tree/issue-67949), but then I was
thinking... ::offsetSet and ::offsetUnset don't really make sense in this
context.

From what I understand, SimpleXML does some magic to make it work without
implementing ArrayAccess.

I think it's cleaner to use ArrayAccess and to throw errors on ::offsetSet
and ::offsetUnset, but I'd like internals' opinion on this.

Regards,

*Florian Margaine*

---

## #77418 — Peter Cowburn — 2014-09-21T21:43:34+00:00

URL: https://externals.io/message/77413#77418 · In reply to: #77413

> Hi list,
>
> The request is so that we can do this:
>
> $html = <<<HTML
> <div>data</div>
> HTML;
> $doc = new DOMDocument;
> $doc->loadHTML($html);
> var_dump($doc->getElementsByTagName('div')[0]->textContent);
>
> I started implementing this on my branch (
> https://github.com/Ralt/php-src/tree/issue-67949), but then I was
> thinking... ::offsetSet and ::offsetUnset don't really make sense in this
> context.
>
> From what I understand, SimpleXML does some magic to make it work without
> implementing ArrayAccess.
>
> I think it's cleaner to use ArrayAccess and to throw errors on ::offsetSet
> and ::offsetUnset, but I'd like internals' opinion on this.
>

The DOM has a very specific API that we should be keeping to, and
encouraging developers to use.

I’d *much* rather see the DOM implementation completed (check out all of
the “not implemented” parts we have), than some shiny, shiny array-style
access to NodeList items. That said, people do like the shiny, shiny.


>
> Regards,
>
> *Florian Margaine*

---

## #77420 — Andrea Faulds — 2014-09-21T22:58:49+00:00

URL: https://externals.io/message/77413#77420 · In reply to: #77418

> The DOM has a very specific API that we should be keeping to, and
> encouraging developers to use.

This is true and we should keep doing this.

> I’d *much* rather see the DOM implementation completed (check out all of
> the “not implemented” parts we have), than some shiny, shiny array-style
> access to NodeList items. That said, people do like the shiny, shiny.

I think this particular request is harmless. Note that this works in JavaScript as well.

--
Andrea Faulds
http://ajf.me/
