3v4l.org

run code in 300+ PHP versions simultaneously
<?php function makeGen(array $array = []): Generator { $item = current($array); yield $item; while($item = next($array)) { yield $item; } } class GeneratorIterator implements \Iterator { private $genMaker; private $genArg; private $current; public function __construct(callable $genMaker, $arg) { $this->genMaker = $genMaker; $this->genArg = $arg; $this->current = $genMaker($arg); } public function current() { return $this->current->current(); } public function key() { return $this->current->key(); } public function rewind() { $this->current = call_user_func($this->genMaker, $this->genArg); } public function valid() { return $this->current->valid(); } public function next() { $this->current->next(); } } $genIterator = new GeneratorIterator('makeGen', [1,2,3]); foreach($genIterator as $key => $value) { echo $key . ' -> ' . $value . "\n"; } echo "\n"; foreach($genIterator as $key => $value) { echo $key . ' -> ' . $value . "\n"; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 14
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 14
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 14
2 jumps found. (Code = 77) Position 1 = 17, Position 2 = 24
Branch analysis from position: 17
2 jumps found. (Code = 78) Position 1 = 18, Position 2 = 24
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
Branch analysis from position: 14
filename:       /in/QOEAs
function name:  (null)
number of ops:  26
compiled vars:  !0 = $genIterator, !1 = $value, !2 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   DECLARE_CLASS                                            'generatoriterator'
   52     1        NEW                                              $3      'GeneratorIterator'
          2        SEND_VAL_EX                                              'makeGen'
          3        SEND_VAL_EX                                              <array>
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !0, $3
   54     6      > FE_RESET_R                                       $6      !0, ->14
          7    > > FE_FETCH_R                                       ~7      $6, !1, ->14
          8    >   ASSIGN                                                   !2, ~7
   55     9        CONCAT                                           ~9      !2, '+-%3E+'
         10        CONCAT                                           ~10     ~9, !1
         11        CONCAT                                           ~11     ~10, '%0A'
         12        ECHO                                                     ~11
   54    13      > JMP                                                      ->7
         14    >   FE_FREE                                                  $6
   57    15        ECHO                                                     '%0A'
   58    16      > FE_RESET_R                                       $12     !0, ->24
         17    > > FE_FETCH_R                                       ~13     $12, !1, ->24
         18    >   ASSIGN                                                   !2, ~13
   59    19        CONCAT                                           ~15     !2, '+-%3E+'
         20        CONCAT                                           ~16     ~15, !1
         21        CONCAT                                           ~17     ~16, '%0A'
         22        ECHO                                                     ~17
   58    23      > JMP                                                      ->17
         24    >   FE_FREE                                                  $12
   60    25      > RETURN                                                   1

Function makegen:
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 = 14, Position 2 = 8
Branch analysis from position: 14
1 jumps found. (Code = 161) Position 1 = -2
Branch analysis from position: 8
2 jumps found. (Code = 44) Position 1 = 14, Position 2 = 8
Branch analysis from position: 14
Branch analysis from position: 8
filename:       /in/QOEAs
function name:  makeGen
number of ops:  15
compiled vars:  !0 = $array, !1 = $item
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV_INIT                                        !0      <array>
          1        GENERATOR_CREATE                                         
    5     2        INIT_FCALL                                               'current'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $2      
          5        ASSIGN                                                   !1, $2
    6     6        YIELD                                                    !1
    8     7      > JMP                                                      ->9
    9     8    >   YIELD                                                    !1
    8     9    >   INIT_FCALL                                               'next'
         10        SEND_REF                                                 !0
         11        DO_ICALL                                         $6      
         12        ASSIGN                                           ~7      !1, $6
         13      > JMPNZ                                                    ~7, ->8
   11    14    > > GENERATOR_RETURN                                         

End of function makegen

Class GeneratorIterator:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QOEAs
function name:  __construct
number of ops:  12
compiled vars:  !0 = $genMaker, !1 = $arg
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   21     2        ASSIGN_OBJ                                               'genMaker'
          3        OP_DATA                                                  !0
   22     4        ASSIGN_OBJ                                               'genArg'
          5        OP_DATA                                                  !1
   23     6        INIT_DYNAMIC_CALL                                        !0
          7        SEND_VAR_EX                                              !1
          8        DO_FCALL                                      0  $5      
          9        ASSIGN_OBJ                                               'current'
         10        OP_DATA                                                  $5
   24    11      > 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/QOEAs
function name:  current
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   FETCH_OBJ_R                                      ~0      'current'
          1        INIT_METHOD_CALL                                         ~0, 'current'
          2        DO_FCALL                                      0  $1      
          3      > RETURN                                                   $1
   29     4*     > RETURN                                                   null

End of function current

Function key:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QOEAs
function name:  key
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   FETCH_OBJ_R                                      ~0      'current'
          1        INIT_METHOD_CALL                                         ~0, 'key'
          2        DO_FCALL                                      0  $1      
          3      > RETURN                                                   $1
   34     4*     > RETURN                                                   null

End of function key

Function rewind:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QOEAs
function name:  rewind
number of ops:  8
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   38     0  E >   FETCH_OBJ_R                                      ~1      'genMaker'
          1        INIT_USER_CALL                                1          'call_user_func', ~1
          2        FETCH_OBJ_R                                      ~2      'genArg'
          3        SEND_USER                                                ~2
          4        DO_FCALL                                      0  $3      
          5        ASSIGN_OBJ                                               'current'
          6        OP_DATA                                                  $3
   39     7      > RETURN                                                   null

End of function rewind

Function valid:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QOEAs
function name:  valid
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   43     0  E >   FETCH_OBJ_R                                      ~0      'current'
          1        INIT_METHOD_CALL                                         ~0, 'valid'
          2        DO_FCALL                                      0  $1      
          3      > RETURN                                                   $1
   44     4*     > RETURN                                                   null

End of function valid

Function next:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QOEAs
function name:  next
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   48     0  E >   FETCH_OBJ_R                                      ~0      'current'
          1        INIT_METHOD_CALL                                         ~0, 'next'
          2        DO_FCALL                                      0          
   49     3      > RETURN                                                   null

End of function next

End of class GeneratorIterator.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
140.36 ms | 1010 KiB | 15 Q