3v4l.org

run code in 300+ PHP versions simultaneously
<?php class IndxedArrayWrapper { private object $properties; public function __construct(array $properties) { $this->properties = (object) []; array_walk($properties, fn($key, $value) => $this->__set($key, $value)); } public function __get(string|int $index): mixed { return $this->properties?->{$index} ?? null; } public function __set(string|int $key, mixed $value): void { $this->properties->{count((array) $this->properties)} = ['key' => $key, 'value' => $value]; } } ['key' => $fruit, 'value' => $colour] = (new IndxedArrayWrapper([ 'apple' => 'red', 'bananna' => 'yellow' ]))->{0}; echo sprintf('At position 0 is a %s %s', $fruit, $colour);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/aNZLa
function name:  (null)
number of ops:  16
compiled vars:  !0 = $fruit, !1 = $colour
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   NEW                                              $2      'IndxedArrayWrapper'
   27     1        SEND_VAL_EX                                              <array>
   26     2        DO_FCALL                                      0          
   29     3        FETCH_OBJ_R                                      ~4      $2, '0'
   26     4        FETCH_LIST_R                                     $5      ~4, 'key'
          5        ASSIGN                                                   !0, $5
          6        FETCH_LIST_R                                     $7      ~4, 'value'
          7        ASSIGN                                                   !1, $7
          8        FREE                                                     ~4
   31     9        INIT_FCALL                                               'sprintf'
         10        SEND_VAL                                                 'At+position+0+is+a+%25s+%25s'
         11        SEND_VAR                                                 !0
         12        SEND_VAR                                                 !1
         13        DO_ICALL                                         $9      
         14        ECHO                                                     $9
         15      > RETURN                                                   1

Class IndxedArrayWrapper:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/aNZLa
function name:  __construct
number of ops:  10
compiled vars:  !0 = $properties
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
    9     1        CAST                                          8  ~2      <array>
          2        ASSIGN_OBJ                                               'properties'
          3        OP_DATA                                                  ~2
   11     4        INIT_FCALL                                               'array_walk'
          5        SEND_REF                                                 !0
          6        DECLARE_LAMBDA_FUNCTION                          ~3      [0]
          7        SEND_VAL                                                 ~3
          8        DO_ICALL                                                 
   12     9      > RETURN                                                   null


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/aNZLa
function name:  {closure}
number of ops:  9
compiled vars:  !0 = $key, !1 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        FETCH_THIS                                       $2      
          3        INIT_METHOD_CALL                                         $2, '__set'
          4        SEND_VAR_EX                                              !0
          5        SEND_VAR_EX                                              !1
          6        DO_FCALL                                      0  $3      
          7      > RETURN                                                   $3
          8*     > RETURN                                                   null

End of Dynamic Function 0

End of function __construct

Function __get:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/aNZLa
function name:  __get
number of ops:  9
compiled vars:  !0 = $index
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
   16     1        FETCH_OBJ_IS                                     ~1      'properties'
          2        JMP_NULL                                         ~2      ~1
          3        FETCH_OBJ_IS                                     ~2      ~1, !0
          4        COALESCE                                         ~3      ~2
          5        QM_ASSIGN                                        ~3      null
          6      > RETURN                                                   ~3
   17     7*       VERIFY_RETURN_TYPE                                       
          8*     > RETURN                                                   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/aNZLa
function name:  __set
number of ops:  11
compiled vars:  !0 = $key, !1 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   21     2        FETCH_OBJ_R                                      ~3      'properties'
          3        CAST                                          7  ~4      ~3
          4        COUNT                                            ~5      ~4
          5        INIT_ARRAY                                       ~7      !0, 'key'
          6        ADD_ARRAY_ELEMENT                                ~7      !1, 'value'
          7        FETCH_OBJ_W                                      $2      'properties'
          8        ASSIGN_OBJ                                               $2, ~5
          9        OP_DATA                                                  ~7
   22    10      > RETURN                                                   null

End of function __set

End of class IndxedArrayWrapper.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
148.88 ms | 1016 KiB | 15 Q