3v4l.org

run code in 300+ PHP versions simultaneously
<?php $xml = '<items><item/><item/><item/></items>'; $dom = new DOMDocument(); $dom->loadXml($xml); $array = iterator_to_array($dom->documentElement->childNodes); var_dump(count($array), $array);
Output for 8.3.0 - 8.3.4
int(3) array(3) { [0]=> object(DOMElement)#5 (27) { ["schemaTypeInfo"]=> NULL ["tagName"]=> string(4) "item" ["className"]=> string(0) "" ["id"]=> string(0) "" ["firstElementChild"]=> NULL ["lastElementChild"]=> NULL ["childElementCount"]=> int(0) ["previousElementSibling"]=> NULL ["nextElementSibling"]=> string(22) "(object value omitted)" ["nodeName"]=> string(4) "item" ["nodeValue"]=> string(0) "" ["nodeType"]=> int(1) ["parentNode"]=> string(22) "(object value omitted)" ["parentElement"]=> string(22) "(object value omitted)" ["childNodes"]=> string(22) "(object value omitted)" ["firstChild"]=> NULL ["lastChild"]=> NULL ["previousSibling"]=> NULL ["nextSibling"]=> string(22) "(object value omitted)" ["attributes"]=> string(22) "(object value omitted)" ["isConnected"]=> bool(true) ["ownerDocument"]=> string(22) "(object value omitted)" ["namespaceURI"]=> NULL ["prefix"]=> string(0) "" ["localName"]=> string(4) "item" ["baseURI"]=> string(1) "/" ["textContent"]=> string(0) "" } [1]=> object(DOMElement)#6 (27) { ["schemaTypeInfo"]=> NULL ["tagName"]=> string(4) "item" ["className"]=> string(0) "" ["id"]=> string(0) "" ["firstElementChild"]=> NULL ["lastElementChild"]=> NULL ["childElementCount"]=> int(0) ["previousElementSibling"]=> string(22) "(object value omitted)" ["nextElementSibling"]=> string(22) "(object value omitted)" ["nodeName"]=> string(4) "item" ["nodeValue"]=> string(0) "" ["nodeType"]=> int(1) ["parentNode"]=> string(22) "(object value omitted)" ["parentElement"]=> string(22) "(object value omitted)" ["childNodes"]=> string(22) "(object value omitted)" ["firstChild"]=> NULL ["lastChild"]=> NULL ["previousSibling"]=> string(22) "(object value omitted)" ["nextSibling"]=> string(22) "(object value omitted)" ["attributes"]=> string(22) "(object value omitted)" ["isConnected"]=> bool(true) ["ownerDocument"]=> string(22) "(object value omitted)" ["namespaceURI"]=> NULL ["prefix"]=> string(0) "" ["localName"]=> string(4) "item" ["baseURI"]=> string(1) "/" ["textContent"]=> string(0) "" } [2]=> object(DOMElement)#7 (27) { ["schemaTypeInfo"]=> NULL ["tagName"]=> string(4) "item" ["className"]=> string(0) "" ["id"]=> string(0) "" ["firstElementChild"]=> NULL ["lastElementChild"]=> NULL ["childElementCount"]=> int(0) ["previousElementSibling"]=> string(22) "(object value omitted)" ["nextElementSibling"]=> NULL ["nodeName"]=> string(4) "item" ["nodeValue"]=> string(0) "" ["nodeType"]=> int(1) ["parentNode"]=> string(22) "(object value omitted)" ["parentElement"]=> string(22) "(object value omitted)" ["childNodes"]=> string(22) "(object value omitted)" ["firstChild"]=> NULL ["lastChild"]=> NULL ["previousSibling"]=> string(22) "(object value omitted)" ["nextSibling"]=> NULL ["attributes"]=> string(22) "(object value omitted)" ["isConnected"]=> bool(true) ["ownerDocument"]=> string(22) "(object value omitted)" ["namespaceURI"]=> NULL ["prefix"]=> string(0) "" ["localName"]=> string(4) "item" ["baseURI"]=> string(1) "/" ["textContent"]=> string(0) "" } }
Output for 8.1.0 - 8.1.27, 8.2.0 - 8.2.17
int(3) array(3) { [0]=> object(DOMElement)#5 (23) { ["schemaTypeInfo"]=> NULL ["tagName"]=> string(4) "item" ["firstElementChild"]=> NULL ["lastElementChild"]=> NULL ["childElementCount"]=> int(0) ["previousElementSibling"]=> NULL ["nextElementSibling"]=> string(22) "(object value omitted)" ["nodeName"]=> string(4) "item" ["nodeValue"]=> string(0) "" ["nodeType"]=> int(1) ["parentNode"]=> string(22) "(object value omitted)" ["childNodes"]=> string(22) "(object value omitted)" ["firstChild"]=> NULL ["lastChild"]=> NULL ["previousSibling"]=> NULL ["nextSibling"]=> string(22) "(object value omitted)" ["attributes"]=> string(22) "(object value omitted)" ["ownerDocument"]=> string(22) "(object value omitted)" ["namespaceURI"]=> NULL ["prefix"]=> string(0) "" ["localName"]=> string(4) "item" ["baseURI"]=> string(1) "/" ["textContent"]=> string(0) "" } [1]=> object(DOMElement)#6 (23) { ["schemaTypeInfo"]=> NULL ["tagName"]=> string(4) "item" ["firstElementChild"]=> NULL ["lastElementChild"]=> NULL ["childElementCount"]=> int(0) ["previousElementSibling"]=> string(22) "(object value omitted)" ["nextElementSibling"]=> string(22) "(object value omitted)" ["nodeName"]=> string(4) "item" ["nodeValue"]=> string(0) "" ["nodeType"]=> int(1) ["parentNode"]=> string(22) "(object value omitted)" ["childNodes"]=> string(22) "(object value omitted)" ["firstChild"]=> NULL ["lastChild"]=> NULL ["previousSibling"]=> string(22) "(object value omitted)" ["nextSibling"]=> string(22) "(object value omitted)" ["attributes"]=> string(22) "(object value omitted)" ["ownerDocument"]=> string(22) "(object value omitted)" ["namespaceURI"]=> NULL ["prefix"]=> string(0) "" ["localName"]=> string(4) "item" ["baseURI"]=> string(1) "/" ["textContent"]=> string(0) "" } [2]=> object(DOMElement)#7 (23) { ["schemaTypeInfo"]=> NULL ["tagName"]=> string(4) "item" ["firstElementChild"]=> NULL ["lastElementChild"]=> NULL ["childElementCount"]=> int(0) ["previousElementSibling"]=> string(22) "(object value omitted)" ["nextElementSibling"]=> NULL ["nodeName"]=> string(4) "item" ["nodeValue"]=> string(0) "" ["nodeType"]=> int(1) ["parentNode"]=> string(22) "(object value omitted)" ["childNodes"]=> string(22) "(object value omitted)" ["firstChild"]=> NULL ["lastChild"]=> NULL ["previousSibling"]=> string(22) "(object value omitted)" ["nextSibling"]=> NULL ["attributes"]=> string(22) "(object value omitted)" ["ownerDocument"]=> string(22) "(object value omitted)" ["namespaceURI"]=> NULL ["prefix"]=> string(0) "" ["localName"]=> string(4) "item" ["baseURI"]=> string(1) "/" ["textContent"]=> string(0) "" } }
Output for 8.0.0 - 8.0.30
int(3) array(3) { [0]=> object(DOMElement)#5 (23) { ["tagName"]=> string(4) "item" ["schemaTypeInfo"]=> NULL ["firstElementChild"]=> NULL ["lastElementChild"]=> NULL ["childElementCount"]=> int(0) ["previousElementSibling"]=> NULL ["nextElementSibling"]=> string(22) "(object value omitted)" ["nodeName"]=> string(4) "item" ["nodeValue"]=> string(0) "" ["nodeType"]=> int(1) ["parentNode"]=> string(22) "(object value omitted)" ["childNodes"]=> string(22) "(object value omitted)" ["firstChild"]=> NULL ["lastChild"]=> NULL ["previousSibling"]=> NULL ["nextSibling"]=> string(22) "(object value omitted)" ["attributes"]=> string(22) "(object value omitted)" ["ownerDocument"]=> string(22) "(object value omitted)" ["namespaceURI"]=> NULL ["prefix"]=> string(0) "" ["localName"]=> string(4) "item" ["baseURI"]=> string(1) "/" ["textContent"]=> string(0) "" } [1]=> object(DOMElement)#6 (23) { ["tagName"]=> string(4) "item" ["schemaTypeInfo"]=> NULL ["firstElementChild"]=> NULL ["lastElementChild"]=> NULL ["childElementCount"]=> int(0) ["previousElementSibling"]=> string(22) "(object value omitted)" ["nextElementSibling"]=> string(22) "(object value omitted)" ["nodeName"]=> string(4) "item" ["nodeValue"]=> string(0) "" ["nodeType"]=> int(1) ["parentNode"]=> string(22) "(object value omitted)" ["childNodes"]=> string(22) "(object value omitted)" ["firstChild"]=> NULL ["lastChild"]=> NULL ["previousSibling"]=> string(22) "(object value omitted)" ["nextSibling"]=> string(22) "(object value omitted)" ["attributes"]=> string(22) "(object value omitted)" ["ownerDocument"]=> string(22) "(object value omitted)" ["namespaceURI"]=> NULL ["prefix"]=> string(0) "" ["localName"]=> string(4) "item" ["baseURI"]=> string(1) "/" ["textContent"]=> string(0) "" } [2]=> object(DOMElement)#7 (23) { ["tagName"]=> string(4) "item" ["schemaTypeInfo"]=> NULL ["firstElementChild"]=> NULL ["lastElementChild"]=> NULL ["childElementCount"]=> int(0) ["previousElementSibling"]=> string(22) "(object value omitted)" ["nextElementSibling"]=> NULL ["nodeName"]=> string(4) "item" ["nodeValue"]=> string(0) "" ["nodeType"]=> int(1) ["parentNode"]=> string(22) "(object value omitted)" ["childNodes"]=> string(22) "(object value omitted)" ["firstChild"]=> NULL ["lastChild"]=> NULL ["previousSibling"]=> string(22) "(object value omitted)" ["nextSibling"]=> NULL ["attributes"]=> string(22) "(object value omitted)" ["ownerDocument"]=> string(22) "(object value omitted)" ["namespaceURI"]=> NULL ["prefix"]=> string(0) "" ["localName"]=> string(4) "item" ["baseURI"]=> string(1) "/" ["textContent"]=> string(0) "" } }
Output for 7.0.20, 7.1.5 - 7.1.20, 7.2.0 - 7.2.33, 7.3.12 - 7.3.33, 7.4.0 - 7.4.33
int(3) array(3) { [0]=> object(DOMElement)#5 (18) { ["tagName"]=> string(4) "item" ["schemaTypeInfo"]=> NULL ["nodeName"]=> string(4) "item" ["nodeValue"]=> string(0) "" ["nodeType"]=> int(1) ["parentNode"]=> string(22) "(object value omitted)" ["childNodes"]=> string(22) "(object value omitted)" ["firstChild"]=> NULL ["lastChild"]=> NULL ["previousSibling"]=> NULL ["nextSibling"]=> string(22) "(object value omitted)" ["attributes"]=> string(22) "(object value omitted)" ["ownerDocument"]=> string(22) "(object value omitted)" ["namespaceURI"]=> NULL ["prefix"]=> string(0) "" ["localName"]=> string(4) "item" ["baseURI"]=> string(1) "/" ["textContent"]=> string(0) "" } [1]=> object(DOMElement)#6 (18) { ["tagName"]=> string(4) "item" ["schemaTypeInfo"]=> NULL ["nodeName"]=> string(4) "item" ["nodeValue"]=> string(0) "" ["nodeType"]=> int(1) ["parentNode"]=> string(22) "(object value omitted)" ["childNodes"]=> string(22) "(object value omitted)" ["firstChild"]=> NULL ["lastChild"]=> NULL ["previousSibling"]=> string(22) "(object value omitted)" ["nextSibling"]=> string(22) "(object value omitted)" ["attributes"]=> string(22) "(object value omitted)" ["ownerDocument"]=> string(22) "(object value omitted)" ["namespaceURI"]=> NULL ["prefix"]=> string(0) "" ["localName"]=> string(4) "item" ["baseURI"]=> string(1) "/" ["textContent"]=> string(0) "" } [2]=> object(DOMElement)#7 (18) { ["tagName"]=> string(4) "item" ["schemaTypeInfo"]=> NULL ["nodeName"]=> string(4) "item" ["nodeValue"]=> string(0) "" ["nodeType"]=> int(1) ["parentNode"]=> string(22) "(object value omitted)" ["childNodes"]=> string(22) "(object value omitted)" ["firstChild"]=> NULL ["lastChild"]=> NULL ["previousSibling"]=> string(22) "(object value omitted)" ["nextSibling"]=> NULL ["attributes"]=> string(22) "(object value omitted)" ["ownerDocument"]=> string(22) "(object value omitted)" ["namespaceURI"]=> NULL ["prefix"]=> string(0) "" ["localName"]=> string(4) "item" ["baseURI"]=> string(1) "/" ["textContent"]=> string(0) "" } }
Output for 7.0.0 - 7.0.14, 7.1.0
int(3) array(3) { [0]=> object(DOMElement)#5 (18) { ["tagName"]=> string(4) "item" ["schemaTypeInfo"]=> NULL ["nodeName"]=> string(4) "item" ["nodeValue"]=> string(0) "" ["nodeType"]=> int(1) ["parentNode"]=> string(22) "(object value omitted)" ["childNodes"]=> string(22) "(object value omitted)" ["firstChild"]=> NULL ["lastChild"]=> NULL ["previousSibling"]=> NULL ["nextSibling"]=> string(22) "(object value omitted)" ["attributes"]=> string(22) "(object value omitted)" ["ownerDocument"]=> string(22) "(object value omitted)" ["namespaceURI"]=> NULL ["prefix"]=> string(0) "" ["localName"]=> string(4) "item" ["baseURI"]=> string(1) "/" ["textContent"]=> string(0) "" } [1]=> object(DOMElement)#6 (18) { ["tagName"]=> string(4) "item" ["schemaTypeInfo"]=> NULL ["nodeName"]=> string(4) "item" ["nodeValue"]=> string(0) "" ["nodeType"]=> int(1) ["parentNode"]=> string(22) "(object value omitted)" ["childNodes"]=> string(22) "(object value omitted)" ["firstChild"]=> NULL ["lastChild"]=> NULL ["previousSibling"]=> string(22) "(object value omitted)" ["nextSibling"]=> string(22) "(object value omitted)" ["attributes"]=> string(22) "(object value omitted)" ["ownerDocument"]=> string(22) "(object value omitted)" ["namespaceURI"]=> NULL ["prefix"]=> string(0) "" ["localName"]=> string(4) "item" ["baseURI"]=> string(1) "/" ["textContent"]=> string(0) "" } [2]=> object(DOMElement)#7 (17) { ["tagName"]=> string(4) "item" ["schemaTypeInfo"]=> NULL ["nodeName"]=> string(4) "item" ["nodeValue"]=> string(0) "" ["nodeType"]=> int(1) ["parentNode"]=> string(22) "(object value omitted)" ["childNodes"]=> string(22) "(object value omitted)" ["firstChild"]=> NULL ["lastChild"]=> NULL ["previousSibling"]=> string(22) "(object value omitted)" ["attributes"]=> string(22) "(object value omitted)" ["ownerDocument"]=> string(22) "(object value omitted)" ["namespaceURI"]=> NULL ["prefix"]=> string(0) "" ["localName"]=> string(4) "item" ["baseURI"]=> string(1) "/" ["textContent"]=> string(0) "" } }
Output for 5.3.11 - 5.3.29, 5.4.1 - 5.4.45, 5.5.24 - 5.5.35, 5.6.8 - 5.6.28
int(3) array(3) { [0]=> object(DOMElement)#4 (18) { ["tagName"]=> string(4) "item" ["schemaTypeInfo"]=> NULL ["nodeName"]=> string(4) "item" ["nodeValue"]=> string(0) "" ["nodeType"]=> int(1) ["parentNode"]=> string(22) "(object value omitted)" ["childNodes"]=> string(22) "(object value omitted)" ["firstChild"]=> NULL ["lastChild"]=> NULL ["previousSibling"]=> NULL ["nextSibling"]=> string(22) "(object value omitted)" ["attributes"]=> string(22) "(object value omitted)" ["ownerDocument"]=> string(22) "(object value omitted)" ["namespaceURI"]=> NULL ["prefix"]=> string(0) "" ["localName"]=> string(4) "item" ["baseURI"]=> string(1) "/" ["textContent"]=> string(0) "" } [1]=> object(DOMElement)#5 (18) { ["tagName"]=> string(4) "item" ["schemaTypeInfo"]=> NULL ["nodeName"]=> string(4) "item" ["nodeValue"]=> string(0) "" ["nodeType"]=> int(1) ["parentNode"]=> string(22) "(object value omitted)" ["childNodes"]=> string(22) "(object value omitted)" ["firstChild"]=> NULL ["lastChild"]=> NULL ["previousSibling"]=> string(22) "(object value omitted)" ["nextSibling"]=> string(22) "(object value omitted)" ["attributes"]=> string(22) "(object value omitted)" ["ownerDocument"]=> string(22) "(object value omitted)" ["namespaceURI"]=> NULL ["prefix"]=> string(0) "" ["localName"]=> string(4) "item" ["baseURI"]=> string(1) "/" ["textContent"]=> string(0) "" } [2]=> object(DOMElement)#6 (17) { ["tagName"]=> string(4) "item" ["schemaTypeInfo"]=> NULL ["nodeName"]=> string(4) "item" ["nodeValue"]=> string(0) "" ["nodeType"]=> int(1) ["parentNode"]=> string(22) "(object value omitted)" ["childNodes"]=> string(22) "(object value omitted)" ["firstChild"]=> NULL ["lastChild"]=> NULL ["previousSibling"]=> string(22) "(object value omitted)" ["attributes"]=> string(22) "(object value omitted)" ["ownerDocument"]=> string(22) "(object value omitted)" ["namespaceURI"]=> NULL ["prefix"]=> string(0) "" ["localName"]=> string(4) "item" ["baseURI"]=> string(1) "/" ["textContent"]=> string(0) "" } }
Output for 5.3.7 - 5.3.10, 5.4.0
int(3) array(3) { [0]=> object(DOMElement)#4 (0) { } [1]=> object(DOMElement)#5 (0) { } [2]=> object(DOMElement)#6 (0) { } }
Output for 5.3.6
int(1) array(1) { [24148384]=> object(DOMElement)#4 (0) { } }
Output for 5.3.5
int(1) array(1) { [47274400]=> object(DOMElement)#4 (0) { } }
Output for 5.3.4
int(1) array(1) { [23427488]=> object(DOMElement)#4 (0) { } }
Output for 5.3.3
int(1) array(1) { [36120992]=> object(DOMElement)#4 (0) { } }
Output for 5.2.0 - 5.2.17, 5.3.0 - 5.3.2
Catchable fatal error: Argument 1 passed to iterator_to_array() must implement interface Traversable, instance of DOMNodeList given in /in/855aX on line 7
Process exited with code 255.
Output for 5.1.0 - 5.1.6
Warning: iterator_to_array() expects parameter 1 to be Traversable, object given in /in/855aX on line 7 int(1) bool(false)
Output for 5.0.0 - 5.0.5
Fatal error: Call to undefined function iterator_to_array() in /in/855aX on line 7
Process exited with code 255.
Output for 4.3.2 - 4.3.11, 4.4.0 - 4.4.9
Fatal error: Cannot instantiate non-existent class: domdocument in /in/855aX on line 5
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Cannot instantiate non-existent class: domdocument in /in/855aX on line 5

preferences:
229.41 ms | 401 KiB | 310 Q