3v4l.org

run code in 300+ PHP versions simultaneously
<?php function gen1() { $x = yield 1; echo "Sup!\n"; $y = yield 2; var_dump($x + $y); } function yfgenerator() { yield from gen1(); echo "Dawg\n"; yield from gen1(); } function yfeiterator() { $arr = [1, 2, 3]; foreach($arr as $val) { yield $val; } } function yfiterator() { yield from []; yield from [1, 2, 3]; /**/ yield from array( "first" => 1, "second" => 2, "third" => 3, ); /**/ } function iterationTest($g) { echo "About to start iteration\n"; foreach($g as $key => $val) { echo "Iteration!\n"; var_dump($key); var_dump($val); } echo "Done with iteration\n"; } function sendingTest($g) { $g->send(10); var_dump($g->current()); $g->send(20); var_dump($g->current()); } //iterationTest(yfiterator()); // iterationTest(gen1()); sendingTest(yfiterator()); sendingTest(yfgenerator()); echo "Done with all tests\n";
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/gc8JT
function name:  (null)
number of ops:  12
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   64     0  E >   INIT_FCALL                                               'sendingtest'
          1        INIT_FCALL                                               'yfiterator'
          2        DO_FCALL                                      0  $0      
          3        SEND_VAR                                                 $0
          4        DO_FCALL                                      0          
   65     5        INIT_FCALL                                               'sendingtest'
          6        INIT_FCALL                                               'yfgenerator'
          7        DO_FCALL                                      0  $2      
          8        SEND_VAR                                                 $2
          9        DO_FCALL                                      0          
   68    10        ECHO                                                     'Done+with+all+tests%0A'
         11      > RETURN                                                   1

Function gen1:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 161) Position 1 = -2
filename:       /in/gc8JT
function name:  gen1
number of ops:  11
compiled vars:  !0 = $x, !1 = $y
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   GENERATOR_CREATE                                         
    4     1        YIELD                                            $2      1
          2        ASSIGN                                                   !0, $2
    5     3        ECHO                                                     'Sup%21%0A'
    6     4        YIELD                                            $4      2
          5        ASSIGN                                                   !1, $4
    7     6        INIT_FCALL                                               'var_dump'
          7        ADD                                              ~6      !0, !1
          8        SEND_VAL                                                 ~6
          9        DO_ICALL                                                 
    8    10      > GENERATOR_RETURN                                         

End of function gen1

Function yfgenerator:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 161) Position 1 = -2
filename:       /in/gc8JT
function name:  yfgenerator
number of ops:  11
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   GENERATOR_CREATE                                         
   11     1        INIT_FCALL                                               'gen1'
          2        DO_FCALL                                      0  $0      
          3        YIELD_FROM                                       ~1      $0
          4        FREE                                                     ~1
   12     5        ECHO                                                     'Dawg%0A'
   13     6        INIT_FCALL                                               'gen1'
          7        DO_FCALL                                      0  $2      
          8        YIELD_FROM                                       ~3      $2
          9        FREE                                                     ~3
   14    10      > GENERATOR_RETURN                                         

End of function yfgenerator

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

End of function yfeiterator

Function yfiterator:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 161) Position 1 = -2
filename:       /in/gc8JT
function name:  yfiterator
number of ops:  8
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   GENERATOR_CREATE                                         
   24     1        YIELD_FROM                                       ~0      <array>
          2        FREE                                                     ~0
   25     3        YIELD_FROM                                       ~1      <array>
          4        FREE                                                     ~1
   28     5        YIELD_FROM                                       ~2      <array>
          6        FREE                                                     ~2
   33     7      > GENERATOR_RETURN                                         

End of function yfiterator

Function iterationtest:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 13
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 13
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
filename:       /in/gc8JT
function name:  iterationTest
number of ops:  16
compiled vars:  !0 = $g, !1 = $val, !2 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   45     0  E >   RECV                                             !0      
   46     1        ECHO                                                     'About+to+start+iteration%0A'
   47     2      > FE_RESET_R                                       $3      !0, ->13
          3    > > FE_FETCH_R                                       ~4      $3, !1, ->13
          4    >   ASSIGN                                                   !2, ~4
   48     5        ECHO                                                     'Iteration%21%0A'
   49     6        INIT_FCALL                                               'var_dump'
          7        SEND_VAR                                                 !2
          8        DO_ICALL                                                 
   50     9        INIT_FCALL                                               'var_dump'
         10        SEND_VAR                                                 !1
         11        DO_ICALL                                                 
   47    12      > JMP                                                      ->3
         13    >   FE_FREE                                                  $3
   52    14        ECHO                                                     'Done+with+iteration%0A'
   53    15      > RETURN                                                   null

End of function iterationtest

Function sendingtest:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/gc8JT
function name:  sendingTest
number of ops:  18
compiled vars:  !0 = $g
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   55     0  E >   RECV                                             !0      
   56     1        INIT_METHOD_CALL                                         !0, 'send'
          2        SEND_VAL_EX                                              10
          3        DO_FCALL                                      0          
   57     4        INIT_FCALL                                               'var_dump'
          5        INIT_METHOD_CALL                                         !0, 'current'
          6        DO_FCALL                                      0  $2      
          7        SEND_VAR                                                 $2
          8        DO_ICALL                                                 
   58     9        INIT_METHOD_CALL                                         !0, 'send'
         10        SEND_VAL_EX                                              20
         11        DO_FCALL                                      0          
   59    12        INIT_FCALL                                               'var_dump'
         13        INIT_METHOD_CALL                                         !0, 'current'
         14        DO_FCALL                                      0  $5      
         15        SEND_VAR                                                 $5
         16        DO_ICALL                                                 
   60    17      > RETURN                                                   null

End of function sendingtest

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
176.24 ms | 1407 KiB | 21 Q