3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Item { private $id; public function __construct(int $id) { $this->id = $id; } public function id() : int { return $this->id; } } class Collection { private $items = []; public function __construct(Item ...$items) { $this->items = $items; } public function item() : Generator { yield from $this->items; } } $items = []; for ($i=0; $i<10; $i++) { $items[] = new Item($i); } $collection = new Collection(...$items); $generator = $collection->item(); printf("\nThe Collection::item() method returns a type of %s, as expected\n", get_class($generator)); printf("However, it yields the following:\n\n"); foreach ($generator as $item) { printf("\tClass: %s. Calling id() method returns %d (%s)\n", get_class($item), $item->id(), gettype($item->id())); } printf("\n\nIt doesn't appear to be possible to hint the yielded type\n\n");
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
2 jumps found. (Code = 44) Position 1 = 11, Position 2 = 3
Branch analysis from position: 11
2 jumps found. (Code = 77) Position 1 = 28, Position 2 = 42
Branch analysis from position: 28
2 jumps found. (Code = 78) Position 1 = 29, Position 2 = 42
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 28
Branch analysis from position: 28
Branch analysis from position: 42
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 42
Branch analysis from position: 3
2 jumps found. (Code = 44) Position 1 = 11, Position 2 = 3
Branch analysis from position: 11
Branch analysis from position: 3
filename:       /in/YcKua
function name:  (null)
number of ops:  47
compiled vars:  !0 = $items, !1 = $i, !2 = $collection, !3 = $generator, !4 = $item
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   ASSIGN                                                   !0, <array>
   29     1        ASSIGN                                                   !1, 0
          2      > JMP                                                      ->9
   30     3    >   NEW                                              $8      'Item'
          4        SEND_VAR_EX                                              !1
          5        DO_FCALL                                      0          
          6        ASSIGN_DIM                                               !0
          7        OP_DATA                                                  $8
   29     8        PRE_INC                                                  !1
          9    >   IS_SMALLER                                               !1, 10
         10      > JMPNZ                                                    ~11, ->3
   33    11    >   NEW                                              $12     'Collection'
         12        SEND_UNPACK                                              !0
         13        CHECK_UNDEF_ARGS                                         
         14        DO_FCALL                                      1          
         15        ASSIGN                                                   !2, $12
   35    16        INIT_METHOD_CALL                                         !2, 'item'
         17        DO_FCALL                                      0  $15     
         18        ASSIGN                                                   !3, $15
   36    19        INIT_FCALL                                               'printf'
         20        SEND_VAL                                                 '%0AThe+Collection%3A%3Aitem%28%29+method+returns+a+type+of+%25s%2C+as+expected%0A'
         21        GET_CLASS                                        ~17     !3
         22        SEND_VAL                                                 ~17
         23        DO_ICALL                                                 
   37    24        INIT_FCALL                                               'printf'
         25        SEND_VAL                                                 'However%2C+it+yields+the+following%3A%0A%0A'
         26        DO_ICALL                                                 
   39    27      > FE_RESET_R                                       $20     !3, ->42
         28    > > FE_FETCH_R                                               $20, !4, ->42
   40    29    >   INIT_FCALL                                               'printf'
         30        SEND_VAL                                                 '%09Class%3A+%25s.+Calling+id%28%29+method+returns+%25d+%28%25s%29%0A'
         31        GET_CLASS                                        ~21     !4
         32        SEND_VAL                                                 ~21
         33        INIT_METHOD_CALL                                         !4, 'id'
         34        DO_FCALL                                      0  $22     
         35        SEND_VAR                                                 $22
         36        INIT_METHOD_CALL                                         !4, 'id'
         37        DO_FCALL                                      0  $23     
         38        GET_TYPE                                         ~24     $23
         39        SEND_VAL                                                 ~24
         40        DO_ICALL                                                 
   39    41      > JMP                                                      ->28
         42    >   FE_FREE                                                  $20
   43    43        INIT_FCALL                                               'printf'
         44        SEND_VAL                                                 '%0A%0AIt+doesn%27t+appear+to+be+possible+to+hint+the+yielded+type%0A%0A'
         45        DO_ICALL                                                 
         46      > RETURN                                                   1

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

End of function id

End of class Item.

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

End of function __construct

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

End of function item

End of class Collection.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
147.63 ms | 952 KiB | 16 Q