3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * This demos a (possible) bug in PHP, which is observed in PHP 5.6, 7.2, 7.3, 7.4 and 8.0 (not tested on 8.1) * * Access behaviour of a SimpleXMLElement changes if that node has a sibling. * * In this example, adding 'fiz' to 'foo' (which is the outer node) will change behaviour when accessing 'bar' (an inner node) */ $xml_1 = new SimpleXMLElement('<foo><bar><baz/></bar></foo>'); print_r($xml_1); // As expected print_r($xml_1->bar); // As expected, $bar contains property $baz, which is an empty SimpleXMLElement $xml_2 = new SimpleXMLElement('<foo><bar><baz/></bar><fiz/></foo>'); print_r($xml_2); // As expected, property $bar is equal to that observed in print_r($xml_1) print_r($xml_2->bar); // UNEXPECTED: property $bar is an array, containing one SimpleXMLElement with property $baz which is an empty SimpleXMLElement
Output for 7.3.13 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.19, 8.3.0 - 8.3.4, 8.3.6 - 8.3.7
SimpleXMLElement Object ( [bar] => SimpleXMLElement Object ( [baz] => SimpleXMLElement Object ( ) ) ) SimpleXMLElement Object ( [baz] => SimpleXMLElement Object ( ) ) SimpleXMLElement Object ( [bar] => SimpleXMLElement Object ( [baz] => SimpleXMLElement Object ( ) ) [fiz] => SimpleXMLElement Object ( ) ) SimpleXMLElement Object ( [0] => SimpleXMLElement Object ( [baz] => SimpleXMLElement Object ( ) ) )
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 SimpleXMLElement Object ( [bar] => SimpleXMLElement Object ( [baz] => SimpleXMLElement Object ( ) ) ) SimpleXMLElement Object ( [baz] => SimpleXMLElement Object ( ) ) SimpleXMLElement Object ( [bar] => SimpleXMLElement Object ( [baz] => SimpleXMLElement Object ( ) ) [fiz] => SimpleXMLElement Object ( ) ) SimpleXMLElement Object ( [0] => SimpleXMLElement Object ( [baz] => SimpleXMLElement Object ( ) ) )

preferences:
141.74 ms | 403 KiB | 145 Q