3v4l.org

run code in 300+ PHP versions simultaneously
<?php function yieldFrom($iter) { $isSubgenerator = $iter instanceof Generator; $received = null; $send = true; while ($iter->valid()) { if ($isSubgenerator) { $next = $send ? $iter->send($received) : $iter->throw($received); } else { $next = $iter->current(); $iter->next(); } try { $received = yield $next; $send = true; } catch (Exception $e) { if ($isSubgenerator) { $received = $e; $send = false; } else { throw $e; } } } // return $isSubgenerator ? $iter->getReturn() : null; }; function gen1() { yield 1; yield 2; yield 3; } $g = gen1(); $g->next(); $x = yieldFrom($g); foreach($x as $val) { var_dump($val); }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 10, Position 2 = 15
Branch analysis from position: 10
2 jumps found. (Code = 78) Position 1 = 11, Position 2 = 15
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
filename:       /in/03hXR
function name:  (null)
number of ops:  17
compiled vars:  !0 = $g, !1 = $x, !2 = $val
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   37     0  E >   INIT_FCALL                                               'gen1'
          1        DO_FCALL                                      0  $3      
          2        ASSIGN                                                   !0, $3
   38     3        INIT_METHOD_CALL                                         !0, 'next'
          4        DO_FCALL                                      0          
   39     5        INIT_FCALL                                               'yieldfrom'
          6        SEND_VAR                                                 !0
          7        DO_FCALL                                      0  $6      
          8        ASSIGN                                                   !1, $6
   41     9      > FE_RESET_R                                       $8      !1, ->15
         10    > > FE_FETCH_R                                               $8, !2, ->15
         11    >   INIT_FCALL                                               'var_dump'
         12        SEND_VAR                                                 !2
         13        DO_ICALL                                                 
         14      > JMP                                                      ->10
         15    >   FE_FREE                                                  $8
         16      > RETURN                                                   1

Function yieldfrom:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 35
Branch analysis from position: 35
2 jumps found. (Code = 44) Position 1 = 38, Position 2 = 7
Branch analysis from position: 38
1 jumps found. (Code = 161) Position 1 = -2
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 20
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 14
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 35
Branch analysis from position: 35
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 35
Branch analysis from position: 35
Found catch point at position: 29
Branch analysis from position: 29
2 jumps found. (Code = 107) Position 1 = 30, Position 2 = -2
Branch analysis from position: 30
2 jumps found. (Code = 43) Position 1 = 31, Position 2 = 34
Branch analysis from position: 31
1 jumps found. (Code = 42) Position 1 = 35
Branch analysis from position: 35
Branch analysis from position: 34
1 jumps found. (Code = 108) Position 1 = -2
filename:       /in/03hXR
function name:  yieldFrom
number of ops:  39
compiled vars:  !0 = $iter, !1 = $isSubgenerator, !2 = $received, !3 = $send, !4 = $next, !5 = $e
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        GENERATOR_CREATE                                         
    4     2        INSTANCEOF                                       ~6      !0, 'Generator'
          3        ASSIGN                                                   !1, ~6
    5     4        ASSIGN                                                   !2, null
    6     5        ASSIGN                                                   !3, <true>
    8     6      > JMP                                                      ->35
    9     7    > > JMPZ                                                     !1, ->20
   10     8    > > JMPZ                                                     !3, ->14
          9    >   INIT_METHOD_CALL                                         !0, 'send'
         10        SEND_VAR_EX                                              !2
         11        DO_FCALL                                      0  $10     
         12        QM_ASSIGN                                        ~11     $10
         13      > JMP                                                      ->18
         14    >   INIT_METHOD_CALL                                         !0, 'throw'
         15        SEND_VAR_EX                                              !2
         16        DO_FCALL                                      0  $12     
         17        QM_ASSIGN                                        ~11     $12
         18    >   ASSIGN                                                   !4, ~11
         19      > JMP                                                      ->25
   12    20    >   INIT_METHOD_CALL                                         !0, 'current'
         21        DO_FCALL                                      0  $14     
         22        ASSIGN                                                   !4, $14
   13    23        INIT_METHOD_CALL                                         !0, 'next'
         24        DO_FCALL                                      0          
   16    25    >   YIELD                                            $17     !4
         26        ASSIGN                                                   !2, $17
   17    27        ASSIGN                                                   !3, <true>
         28      > JMP                                                      ->35
   18    29  E > > CATCH                                       last         'Exception'
   19    30    > > JMPZ                                                     !1, ->34
   20    31    >   ASSIGN                                                   !2, !5
   21    32        ASSIGN                                                   !3, <false>
         33      > JMP                                                      ->35
   23    34    > > THROW                                         0          !5
    8    35    >   INIT_METHOD_CALL                                         !0, 'valid'
         36        DO_FCALL                                      0  $22     
         37      > JMPNZ                                                    $22, ->7
   29    38    > > GENERATOR_RETURN                                         

End of function yieldfrom

Function gen1:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 161) Position 1 = -2
filename:       /in/03hXR
function name:  gen1
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   GENERATOR_CREATE                                         
   32     1        YIELD                                                    1
   33     2        YIELD                                                    2
   34     3        YIELD                                                    3
   35     4      > GENERATOR_RETURN                                         

End of function gen1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
165.08 ms | 1403 KiB | 17 Q