3v4l.org

run code in 500+ 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
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/0EGhe
function name:  (null)
number of ops:  23
compiled vars:  !0 = $xml_1, !1 = $xml_2
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   10     0  E >   NEW                                                  $2      'SimpleXMLElement'
          1        SEND_VAL_EX                                                  '%3Cfoo%3E%3Cbar%3E%3Cbaz%2F%3E%3C%2Fbar%3E%3C%2Ffoo%3E'
          2        DO_FCALL                                          0          
          3        ASSIGN                                                       !0, $2
   12     4        INIT_FCALL                                                   'print_r'
          5        SEND_VAR                                                     !0
          6        DO_ICALL                                                     
   13     7        INIT_FCALL                                                   'print_r'
          8        FETCH_OBJ_R                                          ~6      !0, 'bar'
          9        SEND_VAL                                                     ~6
         10        DO_ICALL                                                     
   15    11        NEW                                                  $8      'SimpleXMLElement'
         12        SEND_VAL_EX                                                  '%3Cfoo%3E%3Cbar%3E%3Cbaz%2F%3E%3C%2Fbar%3E%3Cfiz%2F%3E%3C%2Ffoo%3E'
         13        DO_FCALL                                          0          
         14        ASSIGN                                                       !1, $8
   17    15        INIT_FCALL                                                   'print_r'
         16        SEND_VAR                                                     !1
         17        DO_ICALL                                                     
   18    18        INIT_FCALL                                                   'print_r'
         19        FETCH_OBJ_R                                          ~12     !1, 'bar'
         20        SEND_VAL                                                     ~12
         21        DO_ICALL                                                     
         22      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
117.13 ms | 477 KiB | 8 Q