3v4l.org

run code in 300+ PHP versions simultaneously
<?php final class TypedArray extends ArrayIterator { private $class; public function __construct($class) { $this->class = $class; parent::__construct(array()); } public function offsetSet($index, $newValue) { if (!$newValue instanceof $this->class) { throw new \InvalidArgumentException('Expected instance of ' . $this->class); } } } class A {} $array = new TypedArray(A::class); $array[] = new A; $array['boo'] = new A; foreach ($array as $key => $value) { echo $key . ' -> '; var_dump($value); echo PHP_EOL; } $array[] = 'blah'; /* implements Iterator, ArrayAccess { private $class; private $array; public function __construct($class) { $this->class = $class; $this->array = array(); } public function current() { return current($this->array); } public function key() { return key($this->array); } public function next() { return next($this->array); } public function rewind() { return rewind($this->array); } } */
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 13, Position 2 = 22
Branch analysis from position: 13
2 jumps found. (Code = 78) Position 1 = 14, Position 2 = 22
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
filename:       /in/TWXI2
function name:  (null)
number of ops:  26
compiled vars:  !0 = $array, !1 = $value, !2 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   NEW                                              $3      'TypedArray'
          1        SEND_VAL_EX                                              'A'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $3
   25     4        NEW                                              $7      'A'
          5        DO_FCALL                                      0          
          6        ASSIGN_DIM                                               !0
          7        OP_DATA                                                  $7
   26     8        NEW                                              $10     'A'
          9        DO_FCALL                                      0          
         10        ASSIGN_DIM                                               !0, 'boo'
         11        OP_DATA                                                  $10
   28    12      > FE_RESET_R                                       $12     !0, ->22
         13    > > FE_FETCH_R                                       ~13     $12, !1, ->22
         14    >   ASSIGN                                                   !2, ~13
   29    15        CONCAT                                           ~15     !2, '+-%3E+'
         16        ECHO                                                     ~15
   30    17        INIT_FCALL                                               'var_dump'
         18        SEND_VAR                                                 !1
         19        DO_ICALL                                                 
   31    20        ECHO                                                     '%0A'
   28    21      > JMP                                                      ->13
         22    >   FE_FREE                                                  $12
   34    23        ASSIGN_DIM                                               !0
         24        OP_DATA                                                  'blah'
   66    25      > RETURN                                                   1

Class TypedArray:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/TWXI2
function name:  __construct
number of ops:  7
compiled vars:  !0 = $class
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
    9     1        ASSIGN_OBJ                                               'class'
          2        OP_DATA                                                  !0
   11     3        INIT_STATIC_METHOD_CALL                                  
          4        SEND_VAL_EX                                              <array>
          5        DO_FCALL                                      0          
   12     6      > RETURN                                                   null

End of function __construct

Function offsetset:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 13
Branch analysis from position: 7
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/TWXI2
function name:  offsetSet
number of ops:  14
compiled vars:  !0 = $index, !1 = $newValue
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   16     2        FETCH_OBJ_R                                      ~2      'class'
          3        FETCH_CLASS                                   0  $3      ~2
          4        INSTANCEOF                                       ~4      !1, $3
          5        BOOL_NOT                                         ~5      ~4
          6      > JMPZ                                                     ~5, ->13
   17     7    >   NEW                                              $6      'InvalidArgumentException'
          8        FETCH_OBJ_R                                      ~7      'class'
          9        CONCAT                                           ~8      'Expected+instance+of+', ~7
         10        SEND_VAL_EX                                              ~8
         11        DO_FCALL                                      0          
         12      > THROW                                         0          $6
   19    13    > > RETURN                                                   null

End of function offsetset

End of class TypedArray.

Class A: [no user functions]

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
163.99 ms | 1400 KiB | 15 Q