3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php if (!class_exists("SimpleXMLElement")) { return; } $xml = new SimpleXMLElement(<<<XML <?xml version="1.0" encoding="UTF-8"?> <aa> <bs> <b>b</b> </bs> <cs><c>b</c></cs> <ds><d id="d"></d></ds> <es> <e id="e"></e> </es> <fs><f id="f"></f><f id="f"></f></fs> </aa> XML ); print_r($xml->ds); print_r($xml->es); echo "d@id = {$xml->ds->d['id']}\n"; echo "e@id = {$xml->es->e['id']}\n";
Output for 5.5.27 - 5.5.35, 5.6.11 - 7.1.0
SimpleXMLElement Object ( [0] => SimpleXMLElement Object ( [d] => SimpleXMLElement Object ( [@attributes] => Array ( [id] => d ) ) ) ) SimpleXMLElement Object ( [e] => SimpleXMLElement Object ( [@attributes] => Array ( [id] => e ) ) ) d@id = d e@id = e
Output for 5.4.0 - 5.5.26, 5.6.7 - 5.6.10
SimpleXMLElement Object ( [0] => SimpleXMLElement Object ( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [id] => d ) ) ) ) SimpleXMLElement Object ( [e] => SimpleXMLElement Object ( [@attributes] => Array ( [id] => e ) ) ) d@id = d e@id = e
Output for 5.1.2 - 5.3.29
SimpleXMLElement Object ( [d] => SimpleXMLElement Object ( [@attributes] => Array ( [id] => d ) ) ) SimpleXMLElement Object ( [e] => SimpleXMLElement Object ( [@attributes] => Array ( [id] => e ) ) ) d@id = d e@id = e
Output for 5.0.0 - 5.1.1
SimpleXMLElement Object ( [d] => SimpleXMLElement Object ( ) ) SimpleXMLElement Object ( [e] => SimpleXMLElement Object ( ) ) d@id = d e@id = e
Output for 4.3.0 - 4.4.9