3v4l.org

run code in 500+ PHP versions simultaneously
<?php function getValueRecursive(array $array, ...$keys) { foreach ($keys as $key) { if (!key_exists($key, $array)) { throw new Exception('key path invalid'); } $array = $array[$key]; } return $array; } $foo = [ 'a' => [ 'b' => [ 'c' => "Hallo Welt!" ] ] ]; try { var_export(getValueRecursive($foo, 'a', 'b', 'c')); echo "\n---\n"; var_export(getValueRecursive($foo, 'a', 'b')); echo "\n---\n"; var_export(getValueRecursive($foo, 0, 'b', 'c')); } catch (Exception $e) { echo 'Caught exception: ' . $e->getMessage(); }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 35
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
Found catch point at position: 30
Branch analysis from position: 30
2 jumps found. (Code = 107) Position 1 = 31, Position 2 = -2
Branch analysis from position: 31
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/tKV4h
function name:  (null)
number of ops:  36
compiled vars:  !0 = $foo, !1 = $e
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   14     0  E >   ASSIGN                                                       !0, <array>
   23     1        INIT_FCALL                                                   'var_export'
          2        INIT_FCALL                                                   'getvaluerecursive'
          3        SEND_VAR                                                     !0
          4        SEND_VAL                                                     'a'
          5        SEND_VAL                                                     'b'
          6        SEND_VAL                                                     'c'
          7        DO_FCALL                                          0  $3      
          8        SEND_VAR                                                     $3
          9        DO_ICALL                                                     
   24    10        ECHO                                                         '%0A---%0A'
   25    11        INIT_FCALL                                                   'var_export'
         12        INIT_FCALL                                                   'getvaluerecursive'
         13        SEND_VAR                                                     !0
         14        SEND_VAL                                                     'a'
         15        SEND_VAL                                                     'b'
         16        DO_FCALL                                          0  $5      
         17        SEND_VAR                                                     $5
         18        DO_ICALL                                                     
   26    19        ECHO                                                         '%0A---%0A'
   27    20        INIT_FCALL                                                   'var_export'
         21        INIT_FCALL                                                   'getvaluerecursive'
         22        SEND_VAR                                                     !0
         23        SEND_VAL                                                     0
         24        SEND_VAL                                                     'b'
         25        SEND_VAL                                                     'c'
         26        DO_FCALL                                          0  $7      
         27        SEND_VAR                                                     $7
         28        DO_ICALL                                                     
         29      > JMP                                                          ->35
   28    30  E > > CATCH                                           last         'Exception'
   29    31    >   INIT_METHOD_CALL                                             !1, 'getMessage'
         32        DO_FCALL                                          0  $9      
         33        CONCAT                                               ~10     'Caught+exception%3A+', $9
         34        ECHO                                                         ~10
   30    35    > > RETURN                                                       1

Function getvaluerecursive:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 17
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 17
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 14
Branch analysis from position: 10
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
filename:       /in/tKV4h
function name:  getValueRecursive
number of ops:  20
compiled vars:  !0 = $array, !1 = $keys, !2 = $key
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    4     0  E >   RECV                                                 !0      
          1        RECV_VARIADIC                                        !1      
    5     2      > FE_RESET_R                                           $3      !1, ->17
          3    > > FE_FETCH_R                                                   $3, !2, ->17
    6     4    >   INIT_FCALL                                                   'key_exists'
          5        SEND_VAR                                                     !2
          6        SEND_VAR                                                     !0
          7        DO_ICALL                                             $4      
          8        BOOL_NOT                                             ~5      $4
          9      > JMPZ                                                         ~5, ->14
    7    10    >   NEW                                                  $6      'Exception'
         11        SEND_VAL_EX                                                  'key+path+invalid'
         12        DO_FCALL                                          0          
         13      > THROW                                             0          $6
    9    14    >   FETCH_DIM_R                                          ~8      !0, !2
         15        ASSIGN                                                       !0, ~8
    5    16      > JMP                                                          ->3
         17    >   FE_FREE                                                      $3
   11    18      > RETURN                                                       !0
   12    19*     > RETURN                                                       null

End of function getvaluerecursive

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
214.88 ms | 1448 KiB | 13 Q