3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class XmlArrayAccessIterator implements ArrayAccess, IteratorAggregate { private $xml; private $filePath; private $isUrl; 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 ($this->xml->$offset->count() > 1) { return new self($this->xml->$offset->asXML(), false); } var_dump($this->xml->$offset->asXML()); return $this->xml->$offset; } 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('test.xml', false); echo $xml['note']['to']; //var_dump($xml['note']['recursive']);
Output for 7.0.0 - 7.1.0
Warning: SimpleXMLElement::__construct(): Entity: line 1: parser error : Start tag expected, '<' not found in /in/A7E4J on line 12 Warning: SimpleXMLElement::__construct(): test.xml in /in/A7E4J on line 12 Warning: SimpleXMLElement::__construct(): ^ in /in/A7E4J on line 12 Fatal error: Uncaught Exception: String could not be parsed as XML in /in/A7E4J:12 Stack trace: #0 /in/A7E4J(12): SimpleXMLElement->__construct('test.xml', 0, false) #1 /in/A7E4J(65): XmlArrayAccessIterator->__construct('test.xml', false) #2 {main} thrown in /in/A7E4J on line 12
Process exited with code 255.
Output for 5.1.2 - 5.6.28
Warning: SimpleXMLElement::__construct(): Entity: line 1: parser error : Start tag expected, '<' not found in /in/A7E4J on line 12 Warning: SimpleXMLElement::__construct(): test.xml in /in/A7E4J on line 12 Warning: SimpleXMLElement::__construct(): ^ in /in/A7E4J on line 12 Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /in/A7E4J:12 Stack trace: #0 /in/A7E4J(12): SimpleXMLElement->__construct('test.xml', 0, false) #1 /in/A7E4J(65): XmlArrayAccessIterator->__construct('test.xml', false) #2 {main} thrown in /in/A7E4J on line 12
Process exited with code 255.
Output for 5.0.5, 5.1.1
Fatal error: Uncaught exception 'Exception' with message 'SimpleXMLElement::__construct() expects exactly 1 parameter, 3 given' in /in/A7E4J:12 Stack trace: #0 /in/A7E4J(12): SimpleXMLElement->__construct('test.xml', 0, false) #1 /in/A7E4J(65): XmlArrayAccessIterator->__construct('test.xml', false) #2 {main} thrown in /in/A7E4J on line 12
Process exited with code 255.
Output for 5.1.0
Fatal error: fatal flex scanner internal error--end of buffer missed in /in/A7E4J on line 68
Process exited with code 255.
Output for 5.0.3 - 5.0.4
Fatal error: Uncaught exception 'Exception' with message 'SimpleXMLElement::__construct() expects exactly 1 parameter, 3 given' in /in/A7E4J:12 Stack trace: #0 /in/A7E4J(12): SimpleXMLIterator->__construct('test.xml', 0, false) #1 /in/A7E4J(65): XmlArrayAccessIterator->__construct('test.xml', false) #2 {main} thrown in /in/A7E4J on line 12
Process exited with code 255.
Output for 5.0.0 - 5.0.2
Fatal error: Uncaught exception 'Exception' with message 'SimpleXMLElement::__construct() expects exactly 1 parameter, 3 given' in /in/A7E4J:12 Stack trace: #0 /in/A7E4J(65): XmlArrayAccessIterator->__construct('test.xml', 0, false) #1 {main} thrown in /in/A7E4J on line 12
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting '{' in /in/A7E4J on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting '{' in /in/A7E4J on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `'{'' in /in/A7E4J on line 3
Process exited with code 255.