3v4l.org

run code in 300+ PHP versions simultaneously
<?php function gen1() { echo "Beginning gen1\n"; $x = yield 1; echo "Sup!\n"; $y = yield 2; var_dump($x + $y); } function yfgenerator() { echo "Beginning yfgenerator\n"; yield from gen1(); echo "Dawg\n"; yield from gen1(); } 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(yfgenerator()); echo "====================\n"; //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/AXDaE
function name:  (null)
number of ops:  13
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   48     0  E >   INIT_FCALL                                               'iterationtest'
          1        INIT_FCALL                                               'yfgenerator'
          2        DO_FCALL                                      0  $0      
          3        SEND_VAR                                                 $0
          4        DO_FCALL                                      0          
   49     5        ECHO                                                     '%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%0A'
   51     6        INIT_FCALL                                               'sendingtest'
          7        INIT_FCALL                                               'yfgenerator'
          8        DO_FCALL                                      0  $2      
          9        SEND_VAR                                                 $2
         10        DO_FCALL                                      0          
   54    11        ECHO                                                     'Done+with+all+tests%0A'
         12      > RETURN                                                   1

Function gen1:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 161) Position 1 = -2
filename:       /in/AXDaE
function name:  gen1
number of ops:  12
compiled vars:  !0 = $x, !1 = $y
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   GENERATOR_CREATE                                         
    4     1        ECHO                                                     'Beginning+gen1%0A'
    5     2        YIELD                                            $2      1
          3        ASSIGN                                                   !0, $2
    6     4        ECHO                                                     'Sup%21%0A'
    7     5        YIELD                                            $4      2
          6        ASSIGN                                                   !1, $4
    8     7        INIT_FCALL                                               'var_dump'
          8        ADD                                              ~6      !0, !1
          9        SEND_VAL                                                 ~6
         10        DO_ICALL                                                 
    9    11      > 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/AXDaE
function name:  yfgenerator
number of ops:  12
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   GENERATOR_CREATE                                         
   12     1        ECHO                                                     'Beginning+yfgenerator%0A'
   13     2        INIT_FCALL                                               'gen1'
          3        DO_FCALL                                      0  $0      
          4        YIELD_FROM                                       ~1      $0
          5        FREE                                                     ~1
   14     6        ECHO                                                     'Dawg%0A'
   15     7        INIT_FCALL                                               'gen1'
          8        DO_FCALL                                      0  $2      
          9        YIELD_FROM                                       ~3      $2
         10        FREE                                                     ~3
   16    11      > GENERATOR_RETURN                                         

End of function yfgenerator

Function yfiterator:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 161) Position 1 = -2
filename:       /in/AXDaE
function name:  yfiterator
number of ops:  8
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   GENERATOR_CREATE                                         
   19     1        YIELD_FROM                                       ~0      <array>
          2        FREE                                                     ~0
   20     3        YIELD_FROM                                       ~1      <array>
          4        FREE                                                     ~1
   23     5        YIELD_FROM                                       ~2      <array>
          6        FREE                                                     ~2
   28     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/AXDaE
function name:  iterationTest
number of ops:  16
compiled vars:  !0 = $g, !1 = $val, !2 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   30     0  E >   RECV                                             !0      
   31     1        ECHO                                                     'About+to+start+iteration%0A'
   32     2      > FE_RESET_R                                       $3      !0, ->13
          3    > > FE_FETCH_R                                       ~4      $3, !1, ->13
          4    >   ASSIGN                                                   !2, ~4
   33     5        ECHO                                                     'Iteration%21%0A'
   34     6        INIT_FCALL                                               'var_dump'
          7        SEND_VAR                                                 !2
          8        DO_ICALL                                                 
   35     9        INIT_FCALL                                               'var_dump'
         10        SEND_VAR                                                 !1
         11        DO_ICALL                                                 
   32    12      > JMP                                                      ->3
         13    >   FE_FREE                                                  $3
   37    14        ECHO                                                     'Done+with+iteration%0A'
   38    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/AXDaE
function name:  sendingTest
number of ops:  18
compiled vars:  !0 = $g
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   40     0  E >   RECV                                             !0      
   41     1        INIT_METHOD_CALL                                         !0, 'send'
          2        SEND_VAL_EX                                              10
          3        DO_FCALL                                      0          
   42     4        INIT_FCALL                                               'var_dump'
          5        INIT_METHOD_CALL                                         !0, 'current'
          6        DO_FCALL                                      0  $2      
          7        SEND_VAR                                                 $2
          8        DO_ICALL                                                 
   43     9        INIT_METHOD_CALL                                         !0, 'send'
         10        SEND_VAL_EX                                              20
         11        DO_FCALL                                      0          
   44    12        INIT_FCALL                                               'var_dump'
         13        INIT_METHOD_CALL                                         !0, 'current'
         14        DO_FCALL                                      0  $5      
         15        SEND_VAR                                                 $5
         16        DO_ICALL                                                 
   45    17      > RETURN                                                   null

End of function sendingtest

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
173.49 ms | 1407 KiB | 21 Q