<?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