3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $x = new SimpleXMLElement('<root name="toplevel"></root>'); $f1 = new SimpleXMLElement('<child pos="1">alpha</child>'); $f2 = new SimpleXMLElement('<child pos="2">beta</child>'); $f3 = new SimpleXMLElement('<child pos="3">gamma</child>'); $x->{$f1->getName()} = $f1; $x->{$f2->getName()}[''] = $f2; $x->{$f3->getName()}[] = $f3; echo 'count child=',$x->count(),"\n"; echo $x->asXML(); foreach ( $x->children() as $foo ) { var_dump($foo); } ?>
Output for 5.3.0 - 5.3.29, 5.5.27 - 5.5.35, 5.6.11 - 7.1.0
Warning: main(): Cannot write or create unnamed attribute in /in/d5C9F on line 8 count child=2 <?xml version="1.0"?> <root name="toplevel"><child>alpha</child><child>gamma</child></root> object(SimpleXMLElement)#8 (1) { [0]=> string(5) "alpha" } object(SimpleXMLElement)#9 (1) { [0]=> string(5) "gamma" }
Output for 5.4.28 - 5.5.26, 5.6.7 - 5.6.10
Warning: main(): Cannot write or create unnamed attribute in /in/d5C9F on line 8 count child=2 <?xml version="1.0"?> <root name="toplevel"><child>alpha</child><child>gamma</child></root> object(SimpleXMLElement)#8 (0) { } object(SimpleXMLElement)#9 (1) { [0]=> string(5) "gamma" }
Output for 5.4.0 - 5.4.27
Warning: main(): Cannot write or create unnamed attribute in /in/d5C9F on line 8 count child=2 <?xml version="1.0"?> <root name="toplevel"><child>alpha</child><child>gamma</child></root> object(SimpleXMLElement)#8 (0) { } object(SimpleXMLElement)#9 (0) { }
Output for 5.2.4 - 5.2.17
Warning: main(): Cannot write or create unnamed attribute in /in/d5C9F on line 8 count child= Fatal error: Call to undefined method SimpleXMLElement::count() in /in/d5C9F on line 11
Process exited with code 255.
Output for 5.2.2 - 5.2.3
Warning: main(): Cannot write or create unnamed attribute in /in/d5C9F on line 8 Fatal error: main(): Cannot create unnamed attribute in /in/d5C9F on line 9
Process exited with code 255.
Output for 5.1.3 - 5.2.1
Warning: main(): It is not yet possible to assign complex types to properties in /in/d5C9F on line 7
Process exited with code 139.
Output for 5.0.0 - 5.1.2
Fatal error: Call to undefined method SimpleXMLElement::getName() in /in/d5C9F on line 7
Process exited with code 255.
Output for 4.3.2 - 4.4.9
Fatal error: Cannot instantiate non-existent class: simplexmlelement in /in/d5C9F on line 2
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Cannot instantiate non-existent class: simplexmlelement in /in/d5C9F on line 2