3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getKey($session_key, $is_object_of_type = null) { $current_key = ''; $counter = 0; try { $session_keys_array = explode(':', $session_key); if (!$_SESSION) { throw new Exception("\$_SESSION does not Exist"); } $prev_step = $_SESSION; //checking if keys and value exist foreach ($session_keys_array as $key) { $counter++; $current_key .= '[\'' . $key . '\']'; echo 0; if (array_key_exists($key, $prev_step) && count($session_keys_array) > $counter) { echo 1; $prevStep = $prev_step[$key]; var_dump($prevStep); if (!is_array($prev_step) && count($session_keys_array) > $counter) { echo 2; throw new Exception ("\$_SESSION$current_key is not an array"); } } else if ( is_array($prev_step) && array_key_exists($key, $prev_step) && count($session_keys_array) == $counter ) { echo 3; $result = $prev_step[$key]; } else { echo 4; throw new Exception("\$_SESSION$current_key does not Exist"); } } echo 5; //checking if value is of right type if (!empty($is_object_of_type) && !$result instanceof $is_object_of_type) { echo 6; throw new Exception("\$_SESSION$current_key is not instance of $is_object_of_type"); } echo 7; //if we are here that means we have all safe data } catch(Exception $e) { //TODO:change Exception to SessionException and log this echo 8; $result = null; } echo 9; return $result; } function setSessionTestingData() { $agent = 5; $ticket = 6; $_SESSION = array( 'agent_id' => '2', 'ticket_id' => '3', 'agent' => $agent, 'ticket' => $ticket, 'sub_array' => array( 'sub' => 4, 'agent' => $agent, 'ticket' => $ticket, ), ); return $_SESSION; } $_SESSION = setSessionTestingData(); echo getKey('sub_array:sub');
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/jdCvS
function name:  (null)
number of ops:  9
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   77     0  E >   INIT_FCALL                                               'setsessiontestingdata'
          1        DO_FCALL                                      0  $1      
          2        FETCH_W                      global              $0      '_SESSION'
          3        ASSIGN                                                   $0, $1
   79     4        INIT_FCALL                                               'getkey'
          5        SEND_VAL                                                 'sub_array%3Asub'
          6        DO_FCALL                                      0  $3      
          7        ECHO                                                     $3
          8      > RETURN                                                   1

Function getkey:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 16
Branch analysis from position: 12
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 16
2 jumps found. (Code = 77) Position 1 = 19, Position 2 = 75
Branch analysis from position: 19
2 jumps found. (Code = 78) Position 1 = 20, Position 2 = 75
Branch analysis from position: 20
2 jumps found. (Code = 46) Position 1 = 27, Position 2 = 30
Branch analysis from position: 27
2 jumps found. (Code = 43) Position 1 = 31, Position 2 = 53
Branch analysis from position: 31
2 jumps found. (Code = 46) Position 1 = 40, Position 2 = 43
Branch analysis from position: 40
2 jumps found. (Code = 43) Position 1 = 44, Position 2 = 52
Branch analysis from position: 44
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 52
1 jumps found. (Code = 42) Position 1 = 74
Branch analysis from position: 74
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
Branch analysis from position: 43
Branch analysis from position: 53
2 jumps found. (Code = 46) Position 1 = 55, Position 2 = 57
Branch analysis from position: 55
2 jumps found. (Code = 46) Position 1 = 58, Position 2 = 61
Branch analysis from position: 58
2 jumps found. (Code = 43) Position 1 = 62, Position 2 = 66
Branch analysis from position: 62
1 jumps found. (Code = 42) Position 1 = 74
Branch analysis from position: 74
Branch analysis from position: 66
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 61
Branch analysis from position: 57
Branch analysis from position: 30
Branch analysis from position: 75
2 jumps found. (Code = 46) Position 1 = 80, Position 2 = 84
Branch analysis from position: 80
2 jumps found. (Code = 43) Position 1 = 85, Position 2 = 94
Branch analysis from position: 85
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 94
1 jumps found. (Code = 42) Position 1 = 99
Branch analysis from position: 99
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 84
Branch analysis from position: 75
Found catch point at position: 96
Branch analysis from position: 96
2 jumps found. (Code = 107) Position 1 = 97, Position 2 = -2
Branch analysis from position: 97
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/jdCvS
function name:  getKey
number of ops:  102
compiled vars:  !0 = $session_key, !1 = $is_object_of_type, !2 = $current_key, !3 = $counter, !4 = $session_keys_array, !5 = $prev_step, !6 = $key, !7 = $prevStep, !8 = $result, !9 = $e
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      null
    4     2        ASSIGN                                                   !2, ''
    5     3        ASSIGN                                                   !3, 0
    8     4        INIT_FCALL                                               'explode'
          5        SEND_VAL                                                 '%3A'
          6        SEND_VAR                                                 !0
          7        DO_ICALL                                         $12     
          8        ASSIGN                                                   !4, $12
   10     9        FETCH_R                      global              ~14     '_SESSION'
         10        BOOL_NOT                                         ~15     ~14
         11      > JMPZ                                                     ~15, ->16
   11    12    >   NEW                                              $16     'Exception'
         13        SEND_VAL_EX                                              '%24_SESSION+does+not+Exist'
         14        DO_FCALL                                      0          
         15      > THROW                                         0          $16
   13    16    >   FETCH_R                      global              ~18     '_SESSION'
         17        ASSIGN                                                   !5, ~18
   15    18      > FE_RESET_R                                       $20     !4, ->75
         19    > > FE_FETCH_R                                               $20, !6, ->75
   16    20    >   PRE_INC                                                  !3
   17    21        CONCAT                                           ~22     '%5B%27', !6
         22        CONCAT                                           ~23     ~22, '%27%5D'
         23        ASSIGN_OP                                     8          !2, ~23
   19    24        ECHO                                                     0
   20    25        ARRAY_KEY_EXISTS                                 ~25     !6, !5
         26      > JMPZ_EX                                          ~25     ~25, ->30
         27    >   COUNT                                            ~26     !4
         28        IS_SMALLER                                       ~27     !3, ~26
         29        BOOL                                             ~25     ~27
         30    > > JMPZ                                                     ~25, ->53
   21    31    >   ECHO                                                     1
   22    32        FETCH_DIM_R                                      ~28     !5, !6
         33        ASSIGN                                                   !7, ~28
   23    34        INIT_FCALL                                               'var_dump'
         35        SEND_VAR                                                 !7
         36        DO_ICALL                                                 
   24    37        TYPE_CHECK                                  128  ~31     !5
         38        BOOL_NOT                                         ~32     ~31
         39      > JMPZ_EX                                          ~32     ~32, ->43
         40    >   COUNT                                            ~33     !4
         41        IS_SMALLER                                       ~34     !3, ~33
         42        BOOL                                             ~32     ~34
         43    > > JMPZ                                                     ~32, ->52
   25    44    >   ECHO                                                     2
   26    45        NEW                                              $35     'Exception'
         46        ROPE_INIT                                     3  ~37     '%24_SESSION'
         47        ROPE_ADD                                      1  ~37     ~37, !2
         48        ROPE_END                                      2  ~36     ~37, '+is+not+an+array'
         49        SEND_VAL_EX                                              ~36
         50        DO_FCALL                                      0          
         51      > THROW                                         0          $35
         52    > > JMP                                                      ->74
   29    53    >   TYPE_CHECK                                  128  ~40     !5
         54      > JMPZ_EX                                          ~40     ~40, ->57
   30    55    >   ARRAY_KEY_EXISTS                                 ~41     !6, !5
         56        BOOL                                             ~40     ~41
         57    > > JMPZ_EX                                          ~40     ~40, ->61
   31    58    >   COUNT                                            ~42     !4
         59        IS_EQUAL                                         ~43     !3, ~42
         60        BOOL                                             ~40     ~43
         61    > > JMPZ                                                     ~40, ->66
   33    62    >   ECHO                                                     3
   34    63        FETCH_DIM_R                                      ~44     !5, !6
         64        ASSIGN                                                   !8, ~44
         65      > JMP                                                      ->74
   36    66    >   ECHO                                                     4
   37    67        NEW                                              $46     'Exception'
         68        ROPE_INIT                                     3  ~48     '%24_SESSION'
         69        ROPE_ADD                                      1  ~48     ~48, !2
         70        ROPE_END                                      2  ~47     ~48, '+does+not+Exist'
         71        SEND_VAL_EX                                              ~47
         72        DO_FCALL                                      0          
         73      > THROW                                         0          $46
   15    74    > > JMP                                                      ->19
         75    >   FE_FREE                                                  $20
   40    76        ECHO                                                     5
   42    77        ISSET_ISEMPTY_CV                                 ~51     !1
         78        BOOL_NOT                                         ~52     ~51
         79      > JMPZ_EX                                          ~52     ~52, ->84
         80    >   FETCH_CLASS                                   0  $53     !1
         81        INSTANCEOF                                       ~54     !8, $53
         82        BOOL_NOT                                         ~55     ~54
         83        BOOL                                             ~52     ~55
         84    > > JMPZ                                                     ~52, ->94
   43    85    >   ECHO                                                     6
   44    86        NEW                                              $56     'Exception'
         87        ROPE_INIT                                     4  ~58     '%24_SESSION'
         88        ROPE_ADD                                      1  ~58     ~58, !2
         89        ROPE_ADD                                      2  ~58     ~58, '+is+not+instance+of+'
         90        ROPE_END                                      3  ~57     ~58, !1
         91        SEND_VAL_EX                                              ~57
         92        DO_FCALL                                      0          
         93      > THROW                                         0          $56
   46    94    >   ECHO                                                     7
         95      > JMP                                                      ->99
   48    96  E > > CATCH                                       last         'Exception'
   50    97    >   ECHO                                                     8
   51    98        ASSIGN                                                   !8, null
   53    99    >   ECHO                                                     9
   54   100      > RETURN                                                   !8
   55   101*     > RETURN                                                   null

End of function getkey

Function setsessiontestingdata:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/jdCvS
function name:  setSessionTestingData
number of ops:  15
compiled vars:  !0 = $agent, !1 = $ticket
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   59     0  E >   ASSIGN                                                   !0, 5
   60     1        ASSIGN                                                   !1, 6
   63     2        INIT_ARRAY                                       ~5      '2', 'agent_id'
   64     3        ADD_ARRAY_ELEMENT                                ~5      '3', 'ticket_id'
   65     4        ADD_ARRAY_ELEMENT                                ~5      !0, 'agent'
   66     5        ADD_ARRAY_ELEMENT                                ~5      !1, 'ticket'
   68     6        INIT_ARRAY                                       ~6      4, 'sub'
   69     7        ADD_ARRAY_ELEMENT                                ~6      !0, 'agent'
   70     8        ADD_ARRAY_ELEMENT                                ~6      !1, 'ticket'
          9        ADD_ARRAY_ELEMENT                                ~5      ~6, 'sub_array'
   62    10        FETCH_W                      global              $4      '_SESSION'
         11        ASSIGN                                                   $4, ~5
   74    12        FETCH_R                      global              ~8      '_SESSION'
         13      > RETURN                                                   ~8
   75    14*     > RETURN                                                   null

End of function setsessiontestingdata

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
149.15 ms | 1411 KiB | 19 Q