Re: Request #67949 DOMNodeList should implement ArrayAccess
| From: | Peter Cowburn | Date: | Sun, 21 Sep 2014 21:43:34 +0000 |
| Subject: | Re: Request #67949 DOMNodeList should implement ArrayAccess | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-77418@lists.php.net to get a copy of this message | ||
On 21 September 2014 12:39, Florian Margaine <florian@margaine.com> wrote:
> 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*
>