3v4l.org

run code in 500+ PHP versions simultaneously
<?php class Item { private $id; public function __construct(int $id) { $this->id = $id; } public function id() : int { return $this->id; } } class Items implements IteratorAggregate { private $items = []; public function __construct(Item ...$items) { $this->items = $items; } public function getIterator() : Generator { yield from $this->items; } } class Collection extends IteratorIterator { /** @var Items */ public function __construct(Items $items) { parent::__construct($items); } public function current() : Item { return parent::current(); } } $items = []; for ($i=0; $i<10; $i++) { $items[] = new Item($i); } $collection = new Collection(new Items(...$items)); foreach ($collection as $item) { printf("\tClass: %s. Calling id() method returns %d (%s)\n", get_class($item), $item->id(), gettype($item->id())); }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
2 jumps found. (Code = 44) Position 1 = 12, Position 2 = 4
Branch analysis from position: 12
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
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 35
Branch analysis from position: 4
2 jumps found. (Code = 44) Position 1 = 12, Position 2 = 4
Branch analysis from position: 12
Branch analysis from position: 4
filename:       /in/OH18b
function name:  (null)
number of ops:  37
compiled vars:  !0 = $items, !1 = $i, !2 = $collection, !3 = $item
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   13     0  E >   DECLARE_CLASS                                                'items'
   37     1        ASSIGN                                                       !0, <array>
   38     2        ASSIGN                                                       !1, 0
          3      > JMP                                                          ->10
   39     4    >   NEW                                                  $7      'Item'
          5        SEND_VAR_EX                                                  !1
          6        DO_FCALL                                          0          
          7        ASSIGN_DIM                                                   !0
          8        OP_DATA                                                      $7
   38     9        PRE_INC                                                      !1
         10    >   IS_SMALLER                                                   !1, 10
         11      > JMPNZ                                                        ~10, ->4
   41    12    >   NEW                                                  $11     'Collection'
         13        NEW                                                  $12     'Items'
         14        SEND_UNPACK                                                  !0
         15        CHECK_UNDEF_ARGS                                             
         16        DO_FCALL                                          1          
         17        SEND_VAR_NO_REF_EX                                           $12
         18        DO_FCALL                                          0          
         19        ASSIGN                                                       !2, $11
   43    20      > FE_RESET_R                                           $16     !2, ->35
         21    > > FE_FETCH_R                                                   $16, !3, ->35
   44    22    >   INIT_FCALL                                                   'printf'
         23        SEND_VAL                                                     '%09Class%3A+%25s.+Calling+id%28%29+method+returns+%25d+%28%25s%29%0A'
         24        GET_CLASS                                            ~17     !3
         25        SEND_VAL                                                     ~17
         26        INIT_METHOD_CALL                                             !3, 'id'
         27        DO_FCALL                                          0  $18     
         28        SEND_VAR                                                     $18
         29        INIT_METHOD_CALL                                             !3, 'id'
         30        DO_FCALL                                          0  $19     
         31        GET_TYPE                                             ~20     $19
         32        SEND_VAL                                                     ~20
         33        DO_ICALL                                                     
   43    34      > JMP                                                          ->21
         35    >   FE_FREE                                                      $16
   45    36      > RETURN                                                       1

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

End of function __construct

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

End of function id

End of class Item.

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

End of function __construct

Function getiterator:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 161) Position 1 = -2
filename:       /in/OH18b
function name:  getIterator
number of ops:  5
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   20     0  E >   GENERATOR_CREATE                                             
   22     1        FETCH_OBJ_R                                          ~0      'items'
          2        YIELD_FROM                                           ~1      ~0
          3        FREE                                                         ~1
   23     4      > GENERATOR_RETURN                                             

End of function getiterator

End of class Items.

Class Collection:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OH18b
function name:  __construct
number of ops:  5
compiled vars:  !0 = $items
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   28     0  E >   RECV                                                 !0      
   30     1        INIT_STATIC_METHOD_CALL                                      
          2        SEND_VAR_EX                                                  !0
          3        DO_FCALL                                          0          
   31     4      > 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/OH18b
function name:  current
number of ops:  6
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   34     0  E >   INIT_STATIC_METHOD_CALL                                      'current'
          1        DO_FCALL                                          0  $0      
          2        VERIFY_RETURN_TYPE                                           $0
          3      > RETURN                                                       $0
   35     4*       VERIFY_RETURN_TYPE                                           
          5*     > RETURN                                                       null

End of function current

End of class Collection.

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
162.71 ms | 3058 KiB | 14 Q