3v4l.org

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

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

End of function setsessiontestingdata

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

End of function getkey

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
164.43 ms | 1411 KiB | 19 Q