3v4l.org

run code in 300+ PHP versions simultaneously
<?php function setKey($session_keys, $value) { $current_key = ''; $counter = 0; $prev_step = $_SESSION; try { $session_keys_array = explode(':', $session_keys); foreach ($session_keys_array as $key) { $counter++; $current_key .= '[\'' . $key . '\']'; if (count($session_keys_array) > $counter) { if (is_array($prev_step) && !array_key_exists($key, $prev_step)) { eval('$_SESSION' . $current_key . ' = array();'); } else if (!is_array($prev_step) || (array_key_exists($key, $prev_step)) && !is_array($prev_step[$key]) ) { throw new Exception ("\$_SESSION$current_key is not an array"); } eval('$prevStep = $_SESSION' . $current_key . ';'); } else { eval('$_SESSION' . $current_key . ' = ' . $value . ';'); } } } catch (Exception $e) { //TODO:log notice if Session[currentKey] is not an array echo $e->getMessage(); return false; } return eval('array_key_exists(' . $key . ', '.$prev_step.') && !empty($_SESSION' . $current_key . ');'); } 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(); var_dump(setKey('sub_array:sub:unexistant:none', '4')); !empty($_SESSION['sub_array']['sub']['unexistant']); var_dump(!isset($_SESSION['sub_array']['sub']['unexistant']));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ODnIk
function name:  (null)
number of ops:  25
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   58     0  E >   INIT_FCALL                                               'setsessiontestingdata'
          1        DO_FCALL                                      0  $1      
          2        FETCH_W                      global              $0      '_SESSION'
          3        ASSIGN                                                   $0, $1
   60     4        INIT_FCALL                                               'var_dump'
          5        INIT_FCALL                                               'setkey'
          6        SEND_VAL                                                 'sub_array%3Asub%3Aunexistant%3Anone'
          7        SEND_VAL                                                 '4'
          8        DO_FCALL                                      0  $3      
          9        SEND_VAR                                                 $3
         10        DO_ICALL                                                 
   62    11        FETCH_IS                                         ~5      '_SESSION'
         12        FETCH_DIM_IS                                     ~6      ~5, 'sub_array'
         13        FETCH_DIM_IS                                     ~7      ~6, 'sub'
         14        ISSET_ISEMPTY_DIM_OBJ                         1  ~8      ~7, 'unexistant'
         15        BOOL_NOT                                         ~9      ~8
   63    16        INIT_FCALL                                               'var_dump'
         17        FETCH_IS                                         ~10     '_SESSION'
         18        FETCH_DIM_IS                                     ~11     ~10, 'sub_array'
         19        FETCH_DIM_IS                                     ~12     ~11, 'sub'
         20        ISSET_ISEMPTY_DIM_OBJ                         0  ~13     ~12, 'unexistant'
         21        BOOL_NOT                                         ~14     ~13
         22        SEND_VAL                                                 ~14
         23        DO_ICALL                                                 
         24      > RETURN                                                   1

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

End of function setkey

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

End of function setsessiontestingdata

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
172.48 ms | 1411 KiB | 19 Q