3v4l.org

run code in 300+ PHP versions simultaneously
<?php function gen1() { yield 1; yield 2; yield 3; return 42; } $g = function($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; }; foreach($g(gen1()) as $val) { var_dump($val); }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 8, Position 2 = 13
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 13
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
filename:       /in/aUeJg
function name:  (null)
number of ops:  15
compiled vars:  !0 = $g, !1 = $val
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FaUeJg%3A10%240'
          1        ASSIGN                                                   !0, ~2
   38     2        INIT_DYNAMIC_CALL                                        !0
          3        INIT_FCALL                                               'gen1'
          4        DO_FCALL                                      0  $4      
          5        SEND_VAR_NO_REF_EX                                       $4
          6        DO_FCALL                                      0  $5      
          7      > FE_RESET_R                                       $6      $5, ->13
          8    > > FE_FETCH_R                                               $6, !1, ->13
          9    >   INIT_FCALL                                               'var_dump'
         10        SEND_VAR                                                 !1
         11        DO_ICALL                                                 
         12      > JMP                                                      ->8
         13    >   FE_FREE                                                  $6
         14      > RETURN                                                   1

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

End of function gen1

Function %00%7Bclosure%7D%2Fin%2FaUeJg%3A10%240:
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/aUeJg
function name:  {closure}
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
-------------------------------------------------------------------------------------
   10     0  E >   RECV                                             !0      
          1        GENERATOR_CREATE                                         
   11     2        INSTANCEOF                                       ~6      !0, 'Generator'
          3        ASSIGN                                                   !1, ~6
   12     4        ASSIGN                                                   !2, null
   13     5        ASSIGN                                                   !3, <true>
   15     6      > JMP                                                      ->35
   16     7    > > JMPZ                                                     !1, ->20
   17     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
   19    20    >   INIT_METHOD_CALL                                         !0, 'current'
         21        DO_FCALL                                      0  $14     
         22        ASSIGN                                                   !4, $14
   20    23        INIT_METHOD_CALL                                         !0, 'next'
         24        DO_FCALL                                      0          
   23    25    >   YIELD                                            $17     !4
         26        ASSIGN                                                   !2, $17
   24    27        ASSIGN                                                   !3, <true>
         28      > JMP                                                      ->35
   25    29  E > > CATCH                                       last         'Exception'
   26    30    > > JMPZ                                                     !1, ->34
   27    31    >   ASSIGN                                                   !2, !5
   28    32        ASSIGN                                                   !3, <false>
         33      > JMP                                                      ->35
   30    34    > > THROW                                         0          !5
   15    35    >   INIT_METHOD_CALL                                         !0, 'valid'
         36        DO_FCALL                                      0  $22     
         37      > JMPNZ                                                    $22, ->7
   35    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                                         
   36    45*     > GENERATOR_RETURN                                         

End of function %00%7Bclosure%7D%2Fin%2FaUeJg%3A10%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
196.2 ms | 1411 KiB | 16 Q