3v4l.org

run code in 300+ PHP versions simultaneously
<?php class ArrayMap implements \Iterator { public function __construct(private array $array) { } public function current(): mixed { return current($this->array); } public function next(): void { next($this->array); } public function key(): int|string|null { return key($this->array); } public function valid(): bool { return key($this->array) !== null; } public function rewind(): void { reset($this->array); } } class Aggregate implements \IteratorAggregate { public function __construct(private array $array) { } public function getIterator(): Traversable { return new ArrayMap($this->array); } } class Y { } class Z { } $_1 = new Aggregate([Z::class => Z::class,]); var_dump(1); $_2 = [...iterator_to_array($_1, true)]; var_dump(2); $_3 = [...$_2, Y::class => Z::class]; var_dump(3); $_4 = new Aggregate($_3); var_dump(4); [...$_4]; var_dump(5);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/eRYIJ
function name:  (null)
number of ops:  40
compiled vars:  !0 = $_1, !1 = $_2, !2 = $_3, !3 = $_4
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   DECLARE_CLASS                                            'arraymap'
   35     1        DECLARE_CLASS                                            'aggregate'
   54     2        NEW                                              $4      'Aggregate'
          3        SEND_VAL_EX                                              <array>
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !0, $4
   55     6        INIT_FCALL                                               'var_dump'
          7        SEND_VAL                                                 1
          8        DO_ICALL                                                 
   57     9        INIT_FCALL                                               'iterator_to_array'
         10        SEND_VAR                                                 !0
         11        SEND_VAL                                                 <true>
         12        DO_ICALL                                         $8      
         13        INIT_ARRAY                                       ~9      
         14        ADD_ARRAY_UNPACK                                 ~9      $8
         15        ASSIGN                                                   !1, ~9
   58    16        INIT_FCALL                                               'var_dump'
         17        SEND_VAL                                                 2
         18        DO_ICALL                                                 
   60    19        INIT_ARRAY                                       ~12     
         20        ADD_ARRAY_UNPACK                                 ~12     !1
         21        ADD_ARRAY_ELEMENT                                ~12     'Z', 'Y'
         22        ASSIGN                                                   !2, ~12
   61    23        INIT_FCALL                                               'var_dump'
         24        SEND_VAL                                                 3
         25        DO_ICALL                                                 
   63    26        NEW                                              $15     'Aggregate'
         27        SEND_VAR_EX                                              !2
         28        DO_FCALL                                      0          
         29        ASSIGN                                                   !3, $15
   64    30        INIT_FCALL                                               'var_dump'
         31        SEND_VAL                                                 4
         32        DO_ICALL                                                 
   66    33        INIT_ARRAY                                       ~19     
         34        ADD_ARRAY_UNPACK                                 ~19     !3
         35        FREE                                                     ~19
   67    36        INIT_FCALL                                               'var_dump'
         37        SEND_VAL                                                 5
         38        DO_ICALL                                                 
         39      > RETURN                                                   1

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

End of function __construct

Function current:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/eRYIJ
function name:  current
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   INIT_FCALL                                               'current'
          1        FETCH_OBJ_R                                      ~0      'array'
          2        SEND_VAL                                                 ~0
          3        DO_ICALL                                         $1      
          4      > RETURN                                                   $1
   12     5*       VERIFY_RETURN_TYPE                                       
          6*     > RETURN                                                   null

End of function current

Function next:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/eRYIJ
function name:  next
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   INIT_FCALL                                               'next'
          1        FETCH_OBJ_W                                      $0      'array'
          2        SEND_REF                                                 $0
          3        DO_ICALL                                                 
   17     4      > RETURN                                                   null

End of function next

Function key:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/eRYIJ
function name:  key
number of ops:  8
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   INIT_FCALL                                               'key'
          1        FETCH_OBJ_R                                      ~0      'array'
          2        SEND_VAL                                                 ~0
          3        DO_ICALL                                         $1      
          4        VERIFY_RETURN_TYPE                                       $1
          5      > RETURN                                                   $1
   22     6*       VERIFY_RETURN_TYPE                                       
          7*     > RETURN                                                   null

End of function key

Function valid:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/eRYIJ
function name:  valid
number of ops:  9
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   INIT_FCALL                                               'key'
          1        FETCH_OBJ_R                                      ~0      'array'
          2        SEND_VAL                                                 ~0
          3        DO_ICALL                                         $1      
          4        TYPE_CHECK                                  1020  ~2      $1
          5        VERIFY_RETURN_TYPE                                       ~2
          6      > RETURN                                                   ~2
   27     7*       VERIFY_RETURN_TYPE                                       
          8*     > RETURN                                                   null

End of function valid

Function rewind:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/eRYIJ
function name:  rewind
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   INIT_FCALL                                               'reset'
          1        FETCH_OBJ_W                                      $0      'array'
          2        SEND_REF                                                 $0
          3        DO_ICALL                                                 
   32     4      > RETURN                                                   null

End of function rewind

End of class ArrayMap.

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

End of function __construct

Function getiterator:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/eRYIJ
function name:  getIterator
number of ops:  9
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   43     0  E >   NEW                                              $0      'ArrayMap'
          1        CHECK_FUNC_ARG                                           
          2        FETCH_OBJ_FUNC_ARG                               $1      'array'
          3        SEND_FUNC_ARG                                            $1
          4        DO_FCALL                                      0          
          5        VERIFY_RETURN_TYPE                                       $0
          6      > RETURN                                                   $0
   44     7*       VERIFY_RETURN_TYPE                                       
          8*     > RETURN                                                   null

End of function getiterator

End of class Aggregate.

Class Y: [no user functions]
Class Z: [no user functions]

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
146.62 ms | 1025 KiB | 19 Q