3v4l.org

run code in 300+ PHP versions simultaneously
<?php function gen1() { $x = yield 1; echo "Got $x from a yield\n"; $x = yield 2; echo "Got $x from a yield\n"; $x = yield 3; echo "Got $x from a yield\n"; } function yf($iter) { yield from $iter; } function yfr($iter) { $isSubgenerator = $iter instanceof Generator; foreach($iter as $val) { yield $val; } } // $g = yfr(gen1()); $g = yf(gen1()); $g->next(); var_dump($g->current()); $g->send(10); var_dump($g->current()); $g->send(20); var_dump($g->current());
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/XvsLg
function name:  (null)
number of ops:  30
compiled vars:  !0 = $g
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   INIT_FCALL                                               'yf'
          1        INIT_FCALL                                               'gen1'
          2        DO_FCALL                                      0  $1      
          3        SEND_VAR                                                 $1
          4        DO_FCALL                                      0  $2      
          5        ASSIGN                                                   !0, $2
   25     6        INIT_METHOD_CALL                                         !0, 'next'
          7        DO_FCALL                                      0          
   26     8        INIT_FCALL                                               'var_dump'
          9        INIT_METHOD_CALL                                         !0, 'current'
         10        DO_FCALL                                      0  $5      
         11        SEND_VAR                                                 $5
         12        DO_ICALL                                                 
   27    13        INIT_METHOD_CALL                                         !0, 'send'
         14        SEND_VAL_EX                                              10
         15        DO_FCALL                                      0          
   28    16        INIT_FCALL                                               'var_dump'
         17        INIT_METHOD_CALL                                         !0, 'current'
         18        DO_FCALL                                      0  $8      
         19        SEND_VAR                                                 $8
         20        DO_ICALL                                                 
   29    21        INIT_METHOD_CALL                                         !0, 'send'
         22        SEND_VAL_EX                                              20
         23        DO_FCALL                                      0          
   30    24        INIT_FCALL                                               'var_dump'
         25        INIT_METHOD_CALL                                         !0, 'current'
         26        DO_FCALL                                      0  $11     
         27        SEND_VAR                                                 $11
         28        DO_ICALL                                                 
         29      > RETURN                                                   1

Function gen1:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 161) Position 1 = -2
filename:       /in/XvsLg
function name:  gen1
number of ops:  20
compiled vars:  !0 = $x
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   GENERATOR_CREATE                                         
    4     1        YIELD                                            $1      1
          2        ASSIGN                                                   !0, $1
    5     3        ROPE_INIT                                     3  ~4      'Got+'
          4        ROPE_ADD                                      1  ~4      ~4, !0
          5        ROPE_END                                      2  ~3      ~4, '+from+a+yield%0A'
          6        ECHO                                                     ~3
    6     7        YIELD                                            $6      2
          8        ASSIGN                                                   !0, $6
    7     9        ROPE_INIT                                     3  ~9      'Got+'
         10        ROPE_ADD                                      1  ~9      ~9, !0
         11        ROPE_END                                      2  ~8      ~9, '+from+a+yield%0A'
         12        ECHO                                                     ~8
    8    13        YIELD                                            $11     3
         14        ASSIGN                                                   !0, $11
    9    15        ROPE_INIT                                     3  ~14     'Got+'
         16        ROPE_ADD                                      1  ~14     ~14, !0
         17        ROPE_END                                      2  ~13     ~14, '+from+a+yield%0A'
         18        ECHO                                                     ~13
   10    19      > GENERATOR_RETURN                                         

End of function gen1

Function yf:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 161) Position 1 = -2
filename:       /in/XvsLg
function name:  yf
number of ops:  5
compiled vars:  !0 = $iter
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
          1        GENERATOR_CREATE                                         
   13     2        YIELD_FROM                                       ~1      !0
          3        FREE                                                     ~1
   14     4      > GENERATOR_RETURN                                         

End of function yf

Function yfr:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 8
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 8
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 8
1 jumps found. (Code = 161) Position 1 = -2
Branch analysis from position: 8
filename:       /in/XvsLg
function name:  yfr
number of ops:  10
compiled vars:  !0 = $iter, !1 = $isSubgenerator, !2 = $val
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   RECV                                             !0      
          1        GENERATOR_CREATE                                         
   17     2        INSTANCEOF                                       ~3      !0, 'Generator'
          3        ASSIGN                                                   !1, ~3
   18     4      > FE_RESET_R                                       $5      !0, ->8
          5    > > FE_FETCH_R                                               $5, !2, ->8
   19     6    >   YIELD                                                    !2
   18     7      > JMP                                                      ->5
          8    >   FE_FREE                                                  $5
   21     9      > GENERATOR_RETURN                                         

End of function yfr

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
163.32 ms | 1403 KiB | 17 Q