3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class XmlArrayAccessIterator implements ArrayAccess, IteratorAggregate { private $xml; public function __construct(SimpleXmlIterator $xml) { $this->xml = $xml; } public function offsetExists($offset) { return !is_null($this->xml->$offset); } public function offsetGet($offset) { if ($this->xml->getName() == $offset) { return $this; } return new self($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; } public function __toString() { return (string) $this->xml; } } $xml = '<?xml version="1.0"?> <note> <to>Tove</to> <from>Jani</from> <heading foo="bar">Reminder</heading> <body>Don\'t forget me this weekend!</body> <recursive> <val>2</val> <val>4</val> </recursive> </note>'; $simple = new SimpleXmlIterator($filePath); $xml = new XmlArrayAccessIterator($simple); echo $xml['note']['to'][0]; echo $xml['note']['recursive']['val'][0];
Output for 7.0.0 - 7.1.0
Notice: Undefined variable: filePath in /in/IYrra on line 62 Fatal error: Uncaught Exception: String could not be parsed as XML in /in/IYrra:62 Stack trace: #0 /in/IYrra(62): SimpleXMLElement->__construct('') #1 {main} thrown in /in/IYrra on line 62
Process exited with code 255.
Output for hhvm-3.12.0
Notice: Undefined variable: filePath in /in/IYrra on line 62 Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /in/IYrra:62 Stack trace: #0 /in/IYrra(62): SimpleXMLElement->__construct() #1 {main}
Process exited with code 255.
Output for hhvm-3.10.0
Notice: Undefined variable: filePath in /in/IYrra on line 62 Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /in/IYrra:62 Stack trace: #0 /in/IYrra(62): SimpleXMLIterator->__construct() #1 {main}
Process exited with code 255.
Output for 5.5.0 - 5.6.28
Notice: Undefined variable: filePath in /in/IYrra on line 62 Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /in/IYrra:62 Stack trace: #0 /in/IYrra(62): SimpleXMLElement->__construct('') #1 {main} thrown in /in/IYrra on line 62
Process exited with code 255.
Output for 5.2.3 - 5.4.45
Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /in/IYrra:62 Stack trace: #0 /in/IYrra(62): SimpleXMLElement->__construct('') #1 {main} thrown in /in/IYrra on line 62
Process exited with code 255.
Output for 5.1.2 - 5.2.2
<br /> <b>Fatal error</b>: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /in/IYrra:62 Stack trace: #0 /in/IYrra(62): SimpleXMLElement-&gt;__construct('') #1 {main} thrown in <b>/in/IYrra</b> on line <b>62</b><br />
Process exited with code 255.
Output for 5.0.5 - 5.1.1
<br /> <b>Fatal error</b>: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /in/IYrra:62 Stack trace: #0 /in/IYrra(62): SimpleXMLElement->__construct('') #1 {main} thrown in <b>/in/IYrra</b> on line <b>62</b><br />
Process exited with code 255.
Output for 5.0.3 - 5.0.4
<br /> <b>Fatal error</b>: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /in/IYrra:62 Stack trace: #0 /in/IYrra(62): SimpleXMLIterator->__construct('') #1 {main} thrown in <b>/in/IYrra</b> on line <b>62</b><br />
Process exited with code 255.
Output for 5.0.0 - 5.0.2
<br /> <b>Fatal error</b>: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /in/IYrra:62 Stack trace: #0 {main} thrown in <b>/in/IYrra</b> on line <b>62</b><br />
Process exited with code 255.
Output for 4.4.2 - 4.4.9
<br /> <b>Parse error</b>: syntax error, unexpected T_STRING, expecting '{' in <b>/in/IYrra</b> on line <b>3</b><br />
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
<br /> <b>Parse error</b>: parse error, unexpected T_STRING, expecting '{' in <b>/in/IYrra</b> on line <b>3</b><br />
Process exited with code 255.
Output for 4.3.2 - 4.3.4
<br /> <b>Parse error</b>: parse error, expecting `'{'' in <b>/in/IYrra</b> on line <b>3</b><br />
Process exited with code 255.