- Output for 5.3.0 - 5.3.27, 5.4.0 - 5.4.20
- Parse error: syntax error, unexpected ')' in /in/7c3kr on line 14
Process exited with code 255.
<?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];