3v4l.org

run code in 300+ PHP versions simultaneously
<?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 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Fatal error: Uncaught ValueError: Cannot create attribute with an empty name in /in/d5C9F:8 Stack trace: #0 {main} thrown in /in/d5C9F on line 8
Process exited with code 255.
Output for 5.3.0 - 5.3.29, 5.5.27 - 5.5.38, 5.6.11 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
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.4.45, 5.5.12 - 5.5.26, 5.6.0 - 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, 5.5.0 - 5.5.11
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.1.6, 5.2.0 - 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.0.5, 5.1.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.3.11, 4.4.0 - 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

preferences:
281.94 ms | 401 KiB | 457 Q