3v4l.org

run code in 500+ PHP versions simultaneously
<?php function from() { yield 'a' => 1; yield 'b' => 2; echo "--from return END--\n"; return 'END'; } function gen($from) { var_dump(yield from $from); } $from = from(); $g1 = gen($from); $g2 = gen($from); echo "g1: expect a => 1\n"; var_dump($g1->key()); // $from yield a => 1 var_dump($g1->current()); $g1->next(); // $from yield b => 2 echo "g2: expect b => 2\n"; var_dump($g2->key()); var_dump($g2->current()); echo "expect from return END, gen var_dump(END)\n"; $g2->next(); // $from return END, gen() var_dump, $g2 closed echo "g1: expect gen() var_dump(END), then NULL => NULL, actually no var_dump, NULL => 2\n"; var_dump($g1->key()); // $from already closed, expect gen() var_dump, $g1 closed var_dump($g1->current());
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/C7uM1
function name:  (null)
number of ops:  50
compiled vars:  !0 = $from, !1 = $g1, !2 = $g2
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   16     0  E >   INIT_FCALL                                                   'from'
          1        DO_FCALL                                          0  $3      
          2        ASSIGN                                                       !0, $3
   17     3        INIT_FCALL                                                   'gen'
          4        SEND_VAR                                                     !0
          5        DO_FCALL                                          0  $5      
          6        ASSIGN                                                       !1, $5
   18     7        INIT_FCALL                                                   'gen'
          8        SEND_VAR                                                     !0
          9        DO_FCALL                                          0  $7      
         10        ASSIGN                                                       !2, $7
   20    11        ECHO                                                         'g1%3A+expect+a+%3D%3E+1%0A'
   21    12        INIT_FCALL                                                   'var_dump'
         13        INIT_METHOD_CALL                                             !1, 'key'
         14        DO_FCALL                                          0  $9      
         15        SEND_VAR                                                     $9
         16        DO_ICALL                                                     
   22    17        INIT_FCALL                                                   'var_dump'
         18        INIT_METHOD_CALL                                             !1, 'current'
         19        DO_FCALL                                          0  $11     
         20        SEND_VAR                                                     $11
         21        DO_ICALL                                                     
   23    22        INIT_METHOD_CALL                                             !1, 'next'
         23        DO_FCALL                                          0          
   25    24        ECHO                                                         'g2%3A+expect+b+%3D%3E+2%0A'
   26    25        INIT_FCALL                                                   'var_dump'
         26        INIT_METHOD_CALL                                             !2, 'key'
         27        DO_FCALL                                          0  $14     
         28        SEND_VAR                                                     $14
         29        DO_ICALL                                                     
   27    30        INIT_FCALL                                                   'var_dump'
         31        INIT_METHOD_CALL                                             !2, 'current'
         32        DO_FCALL                                          0  $16     
         33        SEND_VAR                                                     $16
         34        DO_ICALL                                                     
   28    35        ECHO                                                         'expect+from+return+END%2C+gen+var_dump%28END%29%0A'
   29    36        INIT_METHOD_CALL                                             !2, 'next'
         37        DO_FCALL                                          0          
   31    38        ECHO                                                         'g1%3A+expect+gen%28%29+var_dump%28END%29%2C+then+NULL+%3D%3E+NULL%2C+actually+no+var_dump%2C+NULL+%3D%3E+2%0A'
   32    39        INIT_FCALL                                                   'var_dump'
         40        INIT_METHOD_CALL                                             !1, 'key'
         41        DO_FCALL                                          0  $19     
         42        SEND_VAR                                                     $19
         43        DO_ICALL                                                     
   33    44        INIT_FCALL                                                   'var_dump'
         45        INIT_METHOD_CALL                                             !1, 'current'
         46        DO_FCALL                                          0  $21     
         47        SEND_VAR                                                     $21
         48        DO_ICALL                                                     
         49      > RETURN                                                       1

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

End of function from

Function gen:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 161) Position 1 = -2
filename:       /in/C7uM1
function name:  gen
number of ops:  7
compiled vars:  !0 = $from
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   11     0  E >   RECV                                                 !0      
          1        GENERATOR_CREATE                                             
   13     2        INIT_FCALL                                                   'var_dump'
          3        YIELD_FROM                                           ~1      !0
          4        SEND_VAL                                                     ~1
          5        DO_ICALL                                                     
   14     6      > GENERATOR_RETURN                                             

End of function gen

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
127.47 ms | 486 KiB | 11 Q