3v4l.org

run code in 300+ PHP versions simultaneously
<?php $nest = new class([ "first" => [ "I", "am", "a", "animal" => "beaver" ] ]) implements ArrayAccess { public function __construct(array $initial = []) { foreach ($initial as $k => $v) { if (is_array($v)) { $this->$k = new self($v); } else $this->$k = $v; } } public function offsetGet($offset) { if (!isset($this->$offset)) { return ($this->$offset = new self()); } return $this->$offset; } public function offsetSet($offset, $value) { if (is_array($value)) { $this->$offset = new self($value); } else $this->$offset = $value; } public function offsetUnset($offset) { unset($this->$offset); } public function offsetExists($offset) { return isset($this->$offset); } public function array(self $thing = null) { $result = []; if (!$thing) $thing = $this; foreach ($thing as $k => $v) { if ($v instanceof self) { $result[$k] = $this->array($v); } else $result[$k] = $v; } return $result; } public function __invoke(...$args) {} }; $nest[1][2] = "hello"; # write undefined index $nest[5][8][10] = "whatever"; # write more undef index $nest[9][10](); # read undef index and invoke it var_dump($nest->array()); # show array(s), not needed for iteration and whatever ... ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/iV3cF
function name:  (null)
number of ops:  22
compiled vars:  !0 = $nest
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   DECLARE_ANON_CLASS                               <undef> 
          1        NEW                                              $2      $1
    4     2        SEND_VAL_EX                                              <array>
          3        DO_FCALL                                      0          
    2     4        ASSIGN                                                   !0, $2
   53     5        FETCH_DIM_W                                      $5      !0, 1
          6        ASSIGN_DIM                                               $5, 2
          7        OP_DATA                                                  'hello'
   54     8        FETCH_DIM_W                                      $7      !0, 5
          9        FETCH_DIM_W                                      $8      $7, 8
         10        ASSIGN_DIM                                               $8, 10
         11        OP_DATA                                                  'whatever'
   55    12        FETCH_DIM_R                                      ~10     !0, 9
         13        FETCH_DIM_R                                      ~11     ~10, 10
         14        INIT_DYNAMIC_CALL                                        ~11
         15        DO_FCALL                                      0          
   57    16        INIT_FCALL                                               'var_dump'
         17        INIT_METHOD_CALL                                         !0, 'array'
         18        DO_FCALL                                      0  $13     
         19        SEND_VAR                                                 $13
         20        DO_ICALL                                                 
   58    21      > RETURN                                                   1

Class ArrayAccess@anonymous:
Function __construct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 15
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 15
Branch analysis from position: 3
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 12
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
filename:       /in/iV3cF
function name:  __construct
number of ops:  17
compiled vars:  !0 = $initial, !1 = $v, !2 = $k
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   RECV_INIT                                        !0      <array>
   12     1      > FE_RESET_R                                       $3      !0, ->15
          2    > > FE_FETCH_R                                       ~4      $3, !1, ->15
          3    >   ASSIGN                                                   !2, ~4
   13     4        TYPE_CHECK                                  128          !1
          5      > JMPZ                                                     ~6, ->12
   14     6    >   NEW                          self                $8      
          7        SEND_VAR_EX                                              !1
          8        DO_FCALL                                      0          
          9        ASSIGN_OBJ                                               !2
         10        OP_DATA                                                  $8
         11      > JMP                                                      ->14
   15    12    >   ASSIGN_OBJ                                               !2
         13        OP_DATA                                                  !1
   12    14    > > JMP                                                      ->2
         15    >   FE_FREE                                                  $3
   17    16      > RETURN                                                   null

End of function __construct

Function offsetget:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 9
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/iV3cF
function name:  offsetGet
number of ops:  12
compiled vars:  !0 = $offset
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   RECV                                             !0      
   20     1        ISSET_ISEMPTY_PROP_OBJ                           ~1      !0
          2        BOOL_NOT                                         ~2      ~1
          3      > JMPZ                                                     ~2, ->9
   21     4    >   NEW                          self                $4      
          5        DO_FCALL                                      0          
          6        ASSIGN_OBJ                                       ~3      !0
          7        OP_DATA                                                  $4
          8      > RETURN                                                   ~3
   24     9    >   FETCH_OBJ_R                                      ~6      !0
         10      > RETURN                                                   ~6
   25    11*     > RETURN                                                   null

End of function offsetget

Function offsetset:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 10
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/iV3cF
function name:  offsetSet
number of ops:  13
compiled vars:  !0 = $offset, !1 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   28     2        TYPE_CHECK                                  128          !1
          3      > JMPZ                                                     ~2, ->10
   29     4    >   NEW                          self                $4      
          5        SEND_VAR_EX                                              !1
          6        DO_FCALL                                      0          
          7        ASSIGN_OBJ                                               !0
          8        OP_DATA                                                  $4
          9      > JMP                                                      ->12
   30    10    >   ASSIGN_OBJ                                               !0
         11        OP_DATA                                                  !1
   31    12    > > RETURN                                                   null

End of function offsetset

Function offsetunset:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/iV3cF
function name:  offsetUnset
number of ops:  3
compiled vars:  !0 = $offset
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   RECV                                             !0      
          1        UNSET_OBJ                                                !0
          2      > RETURN                                                   null

End of function offsetunset

Function offsetexists:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/iV3cF
function name:  offsetExists
number of ops:  4
compiled vars:  !0 = $offset
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   RECV                                             !0      
          1        ISSET_ISEMPTY_PROP_OBJ                           ~1      !0
          2      > RETURN                                                   ~1
          3*     > RETURN                                                   null

End of function offsetexists

Function array:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 6
Branch analysis from position: 4
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 20
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 20
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 17
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
Branch analysis from position: 6
filename:       /in/iV3cF
function name:  array
number of ops:  23
compiled vars:  !0 = $thing, !1 = $result, !2 = $v, !3 = $k
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   RECV_INIT                                        !0      null
   37     1        ASSIGN                                                   !1, <array>
   39     2        BOOL_NOT                                         ~5      !0
          3      > JMPZ                                                     ~5, ->6
   40     4    >   FETCH_THIS                                       ~6      
          5        ASSIGN                                                   !0, ~6
   42     6    > > FE_RESET_R                                       $8      !0, ->20
          7    > > FE_FETCH_R                                       ~9      $8, !2, ->20
          8    >   ASSIGN                                                   !3, ~9
   43     9        INSTANCEOF                                               !2
         10      > JMPZ                                                     ~11, ->17
   44    11    >   INIT_METHOD_CALL                                         'array'
         12        SEND_VAR_EX                                              !2
         13        DO_FCALL                                      0  $13     
         14        ASSIGN_DIM                                               !1, !3
         15        OP_DATA                                                  $13
         16      > JMP                                                      ->19
   45    17    >   ASSIGN_DIM                                               !1, !3
         18        OP_DATA                                                  !2
   42    19    > > JMP                                                      ->7
         20    >   FE_FREE                                                  $8
   47    21      > RETURN                                                   !1
   48    22*     > RETURN                                                   null

End of function array

Function __invoke:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/iV3cF
function name:  __invoke
number of ops:  2
compiled vars:  !0 = $args
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   50     0  E >   RECV_VARIADIC                                    !0      
          1      > RETURN                                                   null

End of function __invoke

End of class ArrayAccess@anonymous.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
152.15 ms | 1408 KiB | 15 Q