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; } function gen2() { yield from gen1(); } $x = yieldFrom(gen1()); foreach($x as $val) { var_dump($val); }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 12
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 12
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
filename:       /in/k8Ngf
function name:  (null)
number of ops:  14
compiled vars:  !0 = $x, !1 = $val
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   41     0  E >   INIT_FCALL                                               'yieldfrom'
          1        INIT_FCALL                                               'gen1'
          2        DO_FCALL                                      0  $2      
          3        SEND_VAR                                                 $2
          4        DO_FCALL                                      0  $3      
          5        ASSIGN                                                   !0, $3
   43     6      > FE_RESET_R                                       $5      !0, ->12
          7    > > FE_FETCH_R                                               $5, !1, ->12
          8    >   INIT_FCALL                                               'var_dump'
          9        SEND_VAR                                                 !1
         10        DO_ICALL                                                 
         11      > JMP                                                      ->7
         12    >   FE_FREE                                                  $5
         13      > 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
2 jumps found. (Code = 43) Position 1 = 39, Position 2 = 43
Branch analysis from position: 39
1 jumps found. (Code = 42) Position 1 = 44
Branch analysis from position: 44
1 jumps found. (Code = 161) Position 1 = -2
Branch analysis from position: 43
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/k8Ngf
function name:  yieldFrom
number of ops:  46
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
   28    38    > > JMPZ                                                     !1, ->43
         39    >   INIT_METHOD_CALL                                         !0, 'getReturn'
         40        DO_FCALL                                      0  $23     
         41        QM_ASSIGN                                        ~24     $23
         42      > JMP                                                      ->44
         43    >   QM_ASSIGN                                        ~24     null
         44    > > GENERATOR_RETURN                                         
   29    45*     > 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/k8Ngf
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

Function gen2:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 161) Position 1 = -2
filename:       /in/k8Ngf
function name:  gen2
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   37     0  E >   GENERATOR_CREATE                                         
   38     1        INIT_FCALL                                               'gen1'
          2        DO_FCALL                                      0  $0      
          3        YIELD_FROM                                       ~1      $0
          4        FREE                                                     ~1
   39     5      > GENERATOR_RETURN                                         

End of function gen2

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
166.77 ms | 1407 KiB | 18 Q