3v4l.org

run code in 300+ PHP versions simultaneously
<?php $xml = new SimpleXMLElement( '<person> <child role="son"> <child role="daughter"/> </child> <child_under role="daughter"> <child role="son"> <child role="son"/> </child> </child> </person>'); foreach ($xml->children() as $second_gen) { echo ' The person begot a ' . $second_gen['role']; foreach ($second_gen->children() as $third_gen) { echo ' who begot a ' . $third_gen['role'] . ';'; foreach ($third_gen->children() as $fourth_gen) { echo ' and that ' . $third_gen['role'] . ' begot a ' . $fourth_gen['role']; } } } ?>
Output for 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Warning: SimpleXMLElement::__construct(): Entity: line 9: parser error : Opening and ending tag mismatch: child_under line 5 and child in /in/8OBJX on line 2 Warning: SimpleXMLElement::__construct(): </child> in /in/8OBJX on line 2 Warning: SimpleXMLElement::__construct(): ^ in /in/8OBJX on line 2 Fatal error: Uncaught Exception: String could not be parsed as XML in /in/8OBJX:2 Stack trace: #0 /in/8OBJX(2): SimpleXMLElement->__construct('<person>\n <chil...') #1 {main} thrown in /in/8OBJX on line 2
Process exited with code 255.
Output for 7.0.20, 7.1.5 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28
Warning: SimpleXMLElement::__construct(): Entity: line 9: parser error : Opening and ending tag mismatch: child_under line 5 and child in /in/8OBJX on line 3 Warning: SimpleXMLElement::__construct(): </child> in /in/8OBJX on line 3 Warning: SimpleXMLElement::__construct(): ^ in /in/8OBJX on line 3 Fatal error: Uncaught Exception: String could not be parsed as XML in /in/8OBJX:3 Stack trace: #0 /in/8OBJX(3): SimpleXMLElement->__construct('<person>\n <chil...') #1 {main} thrown in /in/8OBJX on line 3
Process exited with code 255.
Output for 7.0.0 - 7.0.14, 7.1.0
Warning: SimpleXMLElement::__construct(): Entity: line 9: parser error : Opening and ending tag mismatch: child_under line 5 and child in /in/8OBJX on line 12 Warning: SimpleXMLElement::__construct(): </child> in /in/8OBJX on line 12 Warning: SimpleXMLElement::__construct(): ^ in /in/8OBJX on line 12 Fatal error: Uncaught Exception: String could not be parsed as XML in /in/8OBJX:12 Stack trace: #0 /in/8OBJX(12): SimpleXMLElement->__construct('<person>\n <chil...') #1 {main} thrown in /in/8OBJX on line 12
Process exited with code 255.
Output for 5.4.29 - 5.4.45, 5.5.24 - 5.5.35, 5.6.7 - 5.6.28
Warning: SimpleXMLElement::__construct(): Entity: line 9: parser error : Opening and ending tag mismatch: child_under line 5 and child in /in/8OBJX on line 12 Warning: SimpleXMLElement::__construct(): </child> in /in/8OBJX on line 12 Warning: SimpleXMLElement::__construct(): ^ in /in/8OBJX on line 12 Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /in/8OBJX:12 Stack trace: #0 /in/8OBJX(12): SimpleXMLElement->__construct('<person>\n <chil...') #1 {main} thrown in /in/8OBJX on line 12
Process exited with code 255.
Output for 5.4.27 - 5.4.28
Warning: SimpleXMLElement::__construct(): Entity: line 9: parser error : Opening and ending tag mismatch: child_under line 5 and child in /in/8OBJX on line 12 Warning: SimpleXMLElement::__construct(): </child> in /in/8OBJX on line 12 Warning: SimpleXMLElement::__construct(): ^ in /in/8OBJX on line 12 Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /in/8OBJX:12 Stack trace: #0 /in/8OBJX(12): SimpleXMLElement->__construct('<person>\n <chiil..') #1 {main} thrown in /in/8OBJX on line 12
Process exited with code 255.
Output for 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.26
Warning: SimpleXMLElement::__construct(): Entity: line 9: parser error : Opening and ending tag mismatch: child_under line 5 and child in /in/8OBJX on line 12 Warning: SimpleXMLElement::__construct(): </child> in /in/8OBJX on line 12 Warning: SimpleXMLElement::__construct(): ^ in /in/8OBJX on line 12 Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /in/8OBJX:12 Stack trace: #0 /in/8OBJX(12): SimpleXMLElement->__construct('<person>? <chil...') #1 {main} thrown in /in/8OBJX on line 12
Process exited with code 255.
Output for 5.0.3 - 5.0.5
Warning: Entity: line 9: parser error : Opening and ending tag mismatch: child_under line 5 and child in /in/8OBJX on line 12 Warning: </child> in /in/8OBJX on line 12 Warning: ^ in /in/8OBJX on line 12 Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /in/8OBJX:12 Stack trace: #0 /in/8OBJX(12): SimpleXMLElement->__construct('<person>? <chil...') #1 {main} thrown in /in/8OBJX on line 12
Process exited with code 255.
Output for 5.0.0 - 5.0.2
Warning: Entity: line 9: parser error : Opening and ending tag mismatch: child_under line 5 and child in /in/8OBJX on line 12 Warning: </child> in /in/8OBJX on line 12 Warning: ^ in /in/8OBJX on line 12 Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /in/8OBJX:12 Stack trace: #0 {main} thrown in /in/8OBJX on line 12
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/8OBJX 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/8OBJX on line 2

preferences:
223.28 ms | 401 KiB | 358 Q