3v4l.org

run code in 300+ PHP versions simultaneously
<?php class StringPathAccess { protected $data = array(); public function __construct(array $data) { $this->data = $data; } public function &get($key) { if (strpos($key, '[]') !== false) { $key = str_replace('[]', '', $key); } $parts = explode('[', $key); $value = &$this->data; foreach ($parts as $part) { $part = rtrim($part, ']'); if (isset($value[$part])) { $value = &$value[$part]; } else { return null; } } return $value; } public function set($key, $value) { $val = &$this->get($key); $val = $value; } } $data = array( 'foo' => array( 'bar' => 'baz' )); $object = new StringPathAccess($data); $test = $object->get('foo[bar]'); var_dump($object->get('foo[bar]')); $object->set('foo[bar]', 'Hello World'); var_dump($object->get('foo[bar]'));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/IotST
function name:  (null)
number of ops:  26
compiled vars:  !0 = $data, !1 = $object, !2 = $test
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   39     0  E >   ASSIGN                                                   !0, <array>
   44     1        NEW                                              $4      'StringPathAccess'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !1, $4
   46     5        INIT_METHOD_CALL                                         !1, 'get'
          6        SEND_VAL_EX                                              'foo%5Bbar%5D'
          7        DO_FCALL                                      0  $7      
          8        ASSIGN                                                   !2, $7
   47     9        INIT_FCALL                                               'var_dump'
         10        INIT_METHOD_CALL                                         !1, 'get'
         11        SEND_VAL_EX                                              'foo%5Bbar%5D'
         12        DO_FCALL                                      0  $9      
         13        SEND_VAR                                                 $9
         14        DO_ICALL                                                 
   48    15        INIT_METHOD_CALL                                         !1, 'set'
         16        SEND_VAL_EX                                              'foo%5Bbar%5D'
         17        SEND_VAL_EX                                              'Hello+World'
         18        DO_FCALL                                      0          
   49    19        INIT_FCALL                                               'var_dump'
         20        INIT_METHOD_CALL                                         !1, 'get'
         21        SEND_VAL_EX                                              'foo%5Bbar%5D'
         22        DO_FCALL                                      0  $12     
         23        SEND_VAR                                                 $12
         24        DO_ICALL                                                 
         25      > RETURN                                                   1

Class StringPathAccess:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/IotST
function name:  __construct
number of ops:  4
compiled vars:  !0 = $data
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   RECV                                             !0      
    8     1        ASSIGN_OBJ                                               'data'
          2        OP_DATA                                                  !0
    9     3      > RETURN                                                   null

End of function __construct

Function get:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 13
Branch analysis from position: 7
2 jumps found. (Code = 77) Position 1 = 21, Position 2 = 35
Branch analysis from position: 21
2 jumps found. (Code = 78) Position 1 = 22, Position 2 = 35
Branch analysis from position: 22
2 jumps found. (Code = 43) Position 1 = 29, Position 2 = 32
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 34
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
Branch analysis from position: 32
Return found
Branch analysis from position: 35
Return found
Branch analysis from position: 35
Branch analysis from position: 13
filename:       /in/IotST
function name:  get
number of ops:  38
compiled vars:  !0 = $key, !1 = $parts, !2 = $value, !3 = $part
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   RECV                                             !0      
   13     1        INIT_FCALL                                               'strpos'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 '%5B%5D'
          4        DO_ICALL                                         $4      
          5        TYPE_CHECK                                  1018          $4
          6      > JMPZ                                                     ~5, ->13
   14     7    >   INIT_FCALL                                               'str_replace'
          8        SEND_VAL                                                 '%5B%5D'
          9        SEND_VAL                                                 ''
         10        SEND_VAR                                                 !0
         11        DO_ICALL                                         $6      
         12        ASSIGN                                                   !0, $6
   17    13    >   INIT_FCALL                                               'explode'
         14        SEND_VAL                                                 '%5B'
         15        SEND_VAR                                                 !0
         16        DO_ICALL                                         $8      
         17        ASSIGN                                                   !1, $8
   18    18        FETCH_OBJ_W                                      $10     'data'
         19        ASSIGN_REF                                               !2, $10
   20    20      > FE_RESET_R                                       $12     !1, ->35
         21    > > FE_FETCH_R                                               $12, !3, ->35
   21    22    >   INIT_FCALL                                               'rtrim'
         23        SEND_VAR                                                 !3
         24        SEND_VAL                                                 '%5D'
         25        DO_ICALL                                         $13     
         26        ASSIGN                                                   !3, $13
   22    27        ISSET_ISEMPTY_DIM_OBJ                         0          !2, !3
         28      > JMPZ                                                     ~15, ->32
   23    29    >   FETCH_DIM_W                                      $16     !2, !3
         30        ASSIGN_REF                                               !2, $16
         31      > JMP                                                      ->34
   25    32    >   FE_FREE                                                  $12
         33      > RETURN_BY_REF                                            null
   20    34    > > JMP                                                      ->21
         35    >   FE_FREE                                                  $12
   29    36      > RETURN_BY_REF                                            !2
   30    37*     > RETURN_BY_REF                                            null

End of function get

Function set:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/IotST
function name:  set
number of ops:  8
compiled vars:  !0 = $key, !1 = $value, !2 = $val
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   34     2        INIT_METHOD_CALL                                         'get'
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0  $3      
          5        ASSIGN_REF                                               !2, $3
   35     6        ASSIGN                                                   !2, !1
   36     7      > RETURN                                                   null

End of function set

End of class StringPathAccess.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
161.35 ms | 1404 KiB | 23 Q