3v4l.org

run code in 300+ PHP versions simultaneously
<?php class XmlArrayAccessIterator implements ArrayAccess, IteratorAggregate { private $xml; public function __construct($filePath, $isUrl = true) { $this->isUrl = $isUrl; $this->xml = new SimpleXmlIterator($filePath, 0, $isUrl); } public function offsetExists($offset) { return !is_null($this->xml->$offset); } public function offsetGet($offset) { if ($this->xml->getName() == $offset) { return $this; } if (is_int($offset)) { var_dump($this->xml); return new self($this->xml[$offset]->asXML(), false); } var_dump((array)$this->xml); return new self($this->xml->$offset->asXML(), false); } public function __toString() { return (string) $this->xml; } public function offsetSet($offset, $value) { throw new RuntimeException('This is readonly. writing to "' . (string) $offset . '" with value "' . (string) $value . '" not possible'); } public function offsetUnset($offset) { throw new RuntimeException('This is readonly. Unsetting "' . (string) $offset . '" not possible'); } public function getIterator() { return $this->xml; } } $str = '<?xml version="1.0"?> <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don\'t forget me this weekend!</body> <recursive> <val>2</val> <val>4</val> </recursive> </note>'; $xml = new XmlArrayAccessIterator($str, false); //echo $xml['note']['to']; echo $xml['note']['recursive']['val']['1'];
Output for git.master, git.master_jit, rfc.property-hooks
Deprecated: Return type of XmlArrayAccessIterator::offsetExists($offset) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/ut9Rh on line 13 Deprecated: Return type of XmlArrayAccessIterator::offsetGet($offset) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/ut9Rh on line 18 Deprecated: Return type of XmlArrayAccessIterator::offsetSet($offset, $value) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/ut9Rh on line 38 Deprecated: Return type of XmlArrayAccessIterator::offsetUnset($offset) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/ut9Rh on line 43 Deprecated: Return type of XmlArrayAccessIterator::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/ut9Rh on line 48 Deprecated: Creation of dynamic property XmlArrayAccessIterator::$isUrl is deprecated in /in/ut9Rh on line 9 array(5) { ["to"]=> string(4) "Tove" ["from"]=> string(4) "Jani" ["heading"]=> string(8) "Reminder" ["body"]=> string(29) "Don't forget me this weekend!" ["recursive"]=> object(SimpleXMLIterator)#3 (1) { ["val"]=> array(2) { [0]=> string(1) "2" [1]=> string(1) "4" } } } Deprecated: Creation of dynamic property XmlArrayAccessIterator::$isUrl is deprecated in /in/ut9Rh on line 9 array(1) { ["val"]=> array(2) { [0]=> string(1) "2" [1]=> string(1) "4" } } Deprecated: Creation of dynamic property XmlArrayAccessIterator::$isUrl is deprecated in /in/ut9Rh on line 9 array(1) { [0]=> string(1) "2" } Deprecated: Creation of dynamic property XmlArrayAccessIterator::$isUrl is deprecated in /in/ut9Rh on line 9 Fatal error: Uncaught Exception: String could not be parsed as XML in /in/ut9Rh:10 Stack trace: #0 /in/ut9Rh(10): SimpleXMLElement->__construct('', 0, false) #1 /in/ut9Rh(30): XmlArrayAccessIterator->__construct(false, false) #2 /in/ut9Rh(73): XmlArrayAccessIterator->offsetGet('1') #3 {main} thrown in /in/ut9Rh on line 10
Process exited with code 255.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
45.37 ms | 404 KiB | 8 Q