3v4l.org

run code in 300+ PHP versions simultaneously
<?php $iter = function(int $a) : \Generator { yield $a + 1; }; $reset = function (int $a) : bool { return $a == 7; }; $init = function () : int { return 3; }; function rotatable(callable $iterate, callable $reset, callable $init) : \Generator { $i = $init(); $gen = $iterate($i); while (TRUE) { yield $i; $i = $gen->current(); $reset($i) and $i = $init(); $gen = $iterate($i); } } function rotate(\Generator $generator) { $current = $generator->current(); $generator->next(); return $current; } $gen = rotatable($iter, $reset, $init); for ($i = 0; $i < 15; $i++) { var_dump(rotate($gen)); }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
2 jumps found. (Code = 44) Position 1 = 23, Position 2 = 14
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
2 jumps found. (Code = 44) Position 1 = 23, Position 2 = 14
Branch analysis from position: 23
Branch analysis from position: 14
filename:       /in/1PYaW
function name:  (null)
number of ops:  24
compiled vars:  !0 = $iter, !1 = $reset, !2 = $init, !3 = $gen, !4 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F1PYaW%3A4%240'
          1        ASSIGN                                                   !0, ~5
    8     2        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F1PYaW%3A8%241'
          3        ASSIGN                                                   !1, ~7
   12     4        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F1PYaW%3A12%242'
          5        ASSIGN                                                   !2, ~9
   33     6        INIT_FCALL                                               'rotatable'
          7        SEND_VAR                                                 !0
          8        SEND_VAR                                                 !1
          9        SEND_VAR                                                 !2
         10        DO_FCALL                                      0  $11     
         11        ASSIGN                                                   !3, $11
   35    12        ASSIGN                                                   !4, 0
         13      > JMP                                                      ->21
   36    14    >   INIT_FCALL                                               'var_dump'
         15        INIT_FCALL                                               'rotate'
         16        SEND_VAR                                                 !3
         17        DO_FCALL                                      0  $14     
         18        SEND_VAR                                                 $14
         19        DO_ICALL                                                 
   35    20        PRE_INC                                                  !4
         21    >   IS_SMALLER                                               !4, 15
         22      > JMPNZ                                                    ~17, ->14
   37    23    > > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2F1PYaW%3A4%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 161) Position 1 = -2
filename:       /in/1PYaW
function name:  {closure}
number of ops:  5
compiled vars:  !0 = $a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
          1        GENERATOR_CREATE                                         
    5     2        ADD                                              ~1      !0, 1
          3        YIELD                                                    ~1
    6     4      > GENERATOR_RETURN                                         

End of function %00%7Bclosure%7D%2Fin%2F1PYaW%3A4%240

Function %00%7Bclosure%7D%2Fin%2F1PYaW%3A8%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/1PYaW
function name:  {closure}
number of ops:  6
compiled vars:  !0 = $a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   RECV                                             !0      
    9     1        IS_EQUAL                                         ~1      !0, 7
          2        VERIFY_RETURN_TYPE                                       ~1
          3      > RETURN                                                   ~1
   10     4*       VERIFY_RETURN_TYPE                                       
          5*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2F1PYaW%3A8%241

Function %00%7Bclosure%7D%2Fin%2F1PYaW%3A12%242:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/1PYaW
function name:  {closure}
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E > > RETURN                                                   3
   14     1*       VERIFY_RETURN_TYPE                                       
          2*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2F1PYaW%3A12%242

Function rotatable:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 28
Branch analysis from position: 28
2 jumps found. (Code = 44) Position 1 = 29, Position 2 = 12
Branch analysis from position: 29
1 jumps found. (Code = 161) Position 1 = -2
Branch analysis from position: 12
2 jumps found. (Code = 46) Position 1 = 20, Position 2 = 24
Branch analysis from position: 20
2 jumps found. (Code = 44) Position 1 = 29, Position 2 = 12
Branch analysis from position: 29
Branch analysis from position: 12
Branch analysis from position: 24
filename:       /in/1PYaW
function name:  rotatable
number of ops:  30
compiled vars:  !0 = $iterate, !1 = $reset, !2 = $init, !3 = $i, !4 = $gen
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        GENERATOR_CREATE                                         
   17     4        INIT_DYNAMIC_CALL                                        !2
          5        DO_FCALL                                      0  $5      
          6        ASSIGN                                                   !3, $5
   18     7        INIT_DYNAMIC_CALL                                        !0
          8        SEND_VAR_EX                                              !3
          9        DO_FCALL                                      0  $7      
         10        ASSIGN                                                   !4, $7
   19    11      > JMP                                                      ->28
   20    12    >   YIELD                                                    !3
   21    13        INIT_METHOD_CALL                                         !4, 'current'
         14        DO_FCALL                                      0  $10     
         15        ASSIGN                                                   !3, $10
   22    16        INIT_DYNAMIC_CALL                                        !1
         17        SEND_VAR_EX                                              !3
         18        DO_FCALL                                      0  $12     
         19      > JMPZ_EX                                          ~13     $12, ->24
         20    >   INIT_DYNAMIC_CALL                                        !2
         21        DO_FCALL                                      0  $14     
         22        ASSIGN                                           ~15     !3, $14
         23        BOOL                                             ~13     ~15
   23    24    >   INIT_DYNAMIC_CALL                                        !0
         25        SEND_VAR_EX                                              !3
         26        DO_FCALL                                      0  $16     
         27        ASSIGN                                                   !4, $16
   19    28    > > JMPNZ                                                    <true>, ->12
   25    29    > > GENERATOR_RETURN                                         

End of function rotatable

Function rotate:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/1PYaW
function name:  rotate
number of ops:  8
compiled vars:  !0 = $generator, !1 = $current
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   RECV                                             !0      
   28     1        INIT_METHOD_CALL                                         !0, 'current'
          2        DO_FCALL                                      0  $2      
          3        ASSIGN                                                   !1, $2
   29     4        INIT_METHOD_CALL                                         !0, 'next'
          5        DO_FCALL                                      0          
   30     6      > RETURN                                                   !1
   31     7*     > RETURN                                                   null

End of function rotate

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
175.61 ms | 1407 KiB | 17 Q