3v4l.org

run code in 300+ PHP versions simultaneously
<?php $tpnb = 5; test(); die(); function test() { global $tpnb; error_log('$tpnb value: ' . $tpnb . ' type:' . gettype($tpnb)); $xmlStruct = <<<EOF <?xml version="1.0" encoding="UTF-8"?> <templates> <object type="obj_1" label="Label for object 1"></object> <object type="obj_2" label="Label for object 2"></object> <object type="obj_3" label="Label for object 3"></object> <object type="obj_4" label="Label for object 4"></object> <object type="obj_5" label="Label for object 5"></object> <object type="obj_6" label="Label for object 6"></object> <object type="obj_7" label="Label for object 7"></object> <object type="obj_8" label="Label for object 8"></object> <object type="obj_9" label="Label for object 9"></object> <object type="obj_10" label="Label for object 10"></object> </templates> EOF; $tplxml = simplexml_load_string($xmlStruct); echo '<table border="1">'; echo '<tr>'; echo'<td style="vertical-align:top"><pre><h1>1: $tpnb</h1>'; // try accessing "object" directly print_r($tplxml->object[$tpnb]); echo '</pre></td>'; echo'<td style="vertical-align:top"><pre><h1>2: (int) $tpnb</h1>'; // try accessing "object" with an index cast print_r($tplxml->object[(int) $tpnb]); echo '</pre></td>'; echo'<td style="vertical-align:top"><pre><h1>3: ($tpnb + 1 - 1)</h1>'; // try accessing "object" by increasing and decreasing the index print_r($tplxml->object[($tpnb + 1 - 1)]); echo '</pre></td>'; echo'<td style="vertical-align:top"><pre><h1>4: temp var</h1>'; // use a temporary variable to re-set the index in the same variable $tpnbx = $tpnb; unset($tpnb); $tpnb = $tpnbx; print_r($tplxml->object[$tpnb]); echo '</pre></td>'; echo '</tr></table>'; }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 79) Position 1 = -2
filename:       /in/OcRGM
function name:  (null)
number of ops:  5
compiled vars:  !0 = $tpnb
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, 5
    5     1        INIT_FCALL_BY_NAME                                       'test'
          2        DO_FCALL                                      0          
    6     3      > EXIT                                                     
   59     4*     > RETURN                                                   1

Function test:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OcRGM
function name:  test
number of ops:  51
compiled vars:  !0 = $tpnb, !1 = $xmlStruct, !2 = $tplxml, !3 = $tpnbx
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   BIND_GLOBAL                                              !0, 'tpnb'
   12     1        INIT_FCALL                                               'error_log'
          2        CONCAT                                           ~4      '%24tpnb+value%3A+', !0
          3        CONCAT                                           ~5      ~4, '+type%3A'
          4        GET_TYPE                                         ~6      !0
          5        CONCAT                                           ~7      ~5, ~6
          6        SEND_VAL                                                 ~7
          7        DO_ICALL                                                 
   14     8        ASSIGN                                                   !1, '%3C%3Fxml+version%3D%221.0%22+encoding%3D%22UTF-8%22%3F%3E%0A%3Ctemplates%3E%0A++++%3Cobject+type%3D%22obj_1%22+label%3D%22Label+for+object+1%22%3E%3C%2Fobject%3E%0A++++%3Cobject+type%3D%22obj_2%22+label%3D%22Label+for+object+2%22%3E%3C%2Fobject%3E%0A++++%3Cobject+type%3D%22obj_3%22+label%3D%22Label+for+object+3%22%3E%3C%2Fobject%3E%0A++++%3Cobject+type%3D%22obj_4%22+label%3D%22Label+for+object+4%22%3E%3C%2Fobject%3E%0A++++%3Cobject+type%3D%22obj_5%22+label%3D%22Label+for+object+5%22%3E%3C%2Fobject%3E%0A++++%3Cobject+type%3D%22obj_6%22+label%3D%22Label+for+object+6%22%3E%3C%2Fobject%3E%0A++++%3Cobject+type%3D%22obj_7%22+label%3D%22Label+for+object+7%22%3E%3C%2Fobject%3E%0A++++%3Cobject+type%3D%22obj_8%22+label%3D%22Label+for+object+8%22%3E%3C%2Fobject%3E%0A++++%3Cobject+type%3D%22obj_9%22+label%3D%22Label+for+object+9%22%3E%3C%2Fobject%3E%0A++++%3Cobject+type%3D%22obj_10%22+label%3D%22Label+for+object+10%22%3E%3C%2Fobject%3E%0A%3C%2Ftemplates%3E'
   29     9        INIT_FCALL                                               'simplexml_load_string'
         10        SEND_VAR                                                 !1
         11        DO_ICALL                                         $10     
         12        ASSIGN                                                   !2, $10
   31    13        ECHO                                                     '%3Ctable+border%3D%221%22%3E'
   32    14        ECHO                                                     '%3Ctr%3E'
   34    15        ECHO                                                     '%3Ctd+style%3D%22vertical-align%3Atop%22%3E%3Cpre%3E%3Ch1%3E1%3A+%24tpnb%3C%2Fh1%3E'
   36    16        INIT_FCALL                                               'print_r'
         17        FETCH_OBJ_R                                      ~12     !2, 'object'
         18        FETCH_DIM_R                                      ~13     ~12, !0
         19        SEND_VAL                                                 ~13
         20        DO_ICALL                                                 
   37    21        ECHO                                                     '%3C%2Fpre%3E%3C%2Ftd%3E'
   39    22        ECHO                                                     '%3Ctd+style%3D%22vertical-align%3Atop%22%3E%3Cpre%3E%3Ch1%3E2%3A+%28int%29+%24tpnb%3C%2Fh1%3E'
   41    23        INIT_FCALL                                               'print_r'
         24        CAST                                          4  ~16     !0
         25        FETCH_OBJ_R                                      ~15     !2, 'object'
         26        FETCH_DIM_R                                      ~17     ~15, ~16
         27        SEND_VAL                                                 ~17
         28        DO_ICALL                                                 
   42    29        ECHO                                                     '%3C%2Fpre%3E%3C%2Ftd%3E'
   44    30        ECHO                                                     '%3Ctd+style%3D%22vertical-align%3Atop%22%3E%3Cpre%3E%3Ch1%3E3%3A+%28%24tpnb+%2B+1+-+1%29%3C%2Fh1%3E'
   47    31        INIT_FCALL                                               'print_r'
         32        ADD                                              ~20     !0, 1
         33        SUB                                              ~21     ~20, 1
         34        FETCH_OBJ_R                                      ~19     !2, 'object'
         35        FETCH_DIM_R                                      ~22     ~19, ~21
         36        SEND_VAL                                                 ~22
         37        DO_ICALL                                                 
   48    38        ECHO                                                     '%3C%2Fpre%3E%3C%2Ftd%3E'
   50    39        ECHO                                                     '%3Ctd+style%3D%22vertical-align%3Atop%22%3E%3Cpre%3E%3Ch1%3E4%3A+temp+var%3C%2Fh1%3E'
   52    40        ASSIGN                                                   !3, !0
   53    41        UNSET_CV                                                 !0
   54    42        ASSIGN                                                   !0, !3
   55    43        INIT_FCALL                                               'print_r'
         44        FETCH_OBJ_R                                      ~26     !2, 'object'
         45        FETCH_DIM_R                                      ~27     ~26, !0
         46        SEND_VAL                                                 ~27
         47        DO_ICALL                                                 
   56    48        ECHO                                                     '%3C%2Fpre%3E%3C%2Ftd%3E'
   58    49        ECHO                                                     '%3C%2Ftr%3E%3C%2Ftable%3E'
   59    50      > RETURN                                                   null

End of function test

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
155.7 ms | 1392 KiB | 19 Q