3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types=1); /** * @template TKey * @template TValue * @implements IteratorAggregate<TKey, TValue> */ final class RewindableGenerator implements IteratorAggregate { /** * @param callable(): Generator<TKey, TValue> $generatorFunction */ public function __construct(private $generatorFunction) {} public function getIterator(): Traversable { return ($this->generatorFunction)(); } } /** * @return Generator<int, int> */ function thousand(): Generator { for ($i = 0; $i < 1000; ++$i) { yield $i; } } $thousand = new RewindableGenerator(thousand(...)); foreach ($thousand as $i); foreach ($thousand as $i); foreach ($thousand as $i);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 8, Position 2 = 10
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 10
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 10
2 jumps found. (Code = 77) Position 1 = 12, Position 2 = 14
Branch analysis from position: 12
2 jumps found. (Code = 78) Position 1 = 13, Position 2 = 14
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
Branch analysis from position: 14
2 jumps found. (Code = 77) Position 1 = 16, Position 2 = 18
Branch analysis from position: 16
2 jumps found. (Code = 78) Position 1 = 17, Position 2 = 18
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
Branch analysis from position: 14
Branch analysis from position: 10
filename:       /in/46Evq
function name:  (null)
number of ops:  20
compiled vars:  !0 = $thousand, !1 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   DECLARE_CLASS                                            'rewindablegenerator'
   33     1        NEW                                              $2      'RewindableGenerator'
          2        INIT_FCALL                                               'thousand'
          3        ZEND_CALLABLE_CONVERT                            ~3      
          4        SEND_VAL_EX                                              ~3
          5        DO_FCALL                                      0          
          6        ASSIGN                                                   !0, $2
   35     7      > FE_RESET_R                                       $6      !0, ->10
          8    > > FE_FETCH_R                                               $6, !1, ->10
          9    > > JMP                                                      ->8
         10    >   FE_FREE                                                  $6
   36    11      > FE_RESET_R                                       $7      !0, ->14
         12    > > FE_FETCH_R                                               $7, !1, ->14
         13    > > JMP                                                      ->12
         14    >   FE_FREE                                                  $7
   37    15      > FE_RESET_R                                       $8      !0, ->18
         16    > > FE_FETCH_R                                               $8, !1, ->18
         17    > > JMP                                                      ->16
         18    >   FE_FREE                                                  $8
         19      > RETURN                                                   1

Function thousand:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
2 jumps found. (Code = 44) Position 1 = 7, Position 2 = 3
Branch analysis from position: 7
1 jumps found. (Code = 161) Position 1 = -2
Branch analysis from position: 3
2 jumps found. (Code = 44) Position 1 = 7, Position 2 = 3
Branch analysis from position: 7
Branch analysis from position: 3
filename:       /in/46Evq
function name:  thousand
number of ops:  8
compiled vars:  !0 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   GENERATOR_CREATE                                         
   28     1        ASSIGN                                                   !0, 0
          2      > JMP                                                      ->5
   29     3    >   YIELD                                                    !0
   28     4        PRE_INC                                                  !0
          5    >   IS_SMALLER                                               !0, 1000
          6      > JMPNZ                                                    ~4, ->3
   31     7    > > GENERATOR_RETURN                                         

End of function thousand

Class RewindableGenerator:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/46Evq
function name:  __construct
number of ops:  4
compiled vars:  !0 = $generatorFunction
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   RECV                                             !0      
          1        ASSIGN_OBJ                                               'generatorFunction'
          2        OP_DATA                                                  !0
          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/46Evq
function name:  getIterator
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   FETCH_OBJ_R                                      ~0      'generatorFunction'
          1        INIT_DYNAMIC_CALL                                        ~0
          2        DO_FCALL                                      0  $1      
          3        VERIFY_RETURN_TYPE                                       $1
          4      > RETURN                                                   $1
   20     5*       VERIFY_RETURN_TYPE                                       
          6*     > RETURN                                                   null

End of function getiterator

End of class RewindableGenerator.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
139.78 ms | 1003 KiB | 14 Q