3v4l.org

run code in 300+ PHP versions simultaneously
<?php function gen() { echo "1\n"; $ret = (yield 'yield1'); echo "2\n"; var_dump($ret); echo "3\n"; $ret = (yield 'yield2'); echo "4\n"; var_dump($ret); } $gen = gen(); var_dump($gen->current()); // string(6) "yield1" var_dump($gen->send('ret1')); // string(4) "ret1" (the first var_dump in gen) // string(6) "yield2" (the var_dump of the ->send() return value) var_dump($gen->send('ret2')); // string(4) "ret2" (again from within gen) // NULL (the return value of ->send())
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/4hu4c
function name:  (null)
number of ops:  21
compiled vars:  !0 = $gen
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   INIT_FCALL                                               'gen'
          1        DO_FCALL                                      0  $1      
          2        ASSIGN                                                   !0, $1
   14     3        INIT_FCALL                                               'var_dump'
          4        INIT_METHOD_CALL                                         !0, 'current'
          5        DO_FCALL                                      0  $3      
          6        SEND_VAR                                                 $3
          7        DO_ICALL                                                 
   15     8        INIT_FCALL                                               'var_dump'
          9        INIT_METHOD_CALL                                         !0, 'send'
         10        SEND_VAL_EX                                              'ret1'
         11        DO_FCALL                                      0  $5      
         12        SEND_VAR                                                 $5
         13        DO_ICALL                                                 
   17    14        INIT_FCALL                                               'var_dump'
         15        INIT_METHOD_CALL                                         !0, 'send'
         16        SEND_VAL_EX                                              'ret2'
         17        DO_FCALL                                      0  $7      
         18        SEND_VAR                                                 $7
         19        DO_ICALL                                                 
   18    20      > RETURN                                                   1

Function gen:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 161) Position 1 = -2
filename:       /in/4hu4c
function name:  gen
number of ops:  16
compiled vars:  !0 = $ret
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   GENERATOR_CREATE                                         
    3     1        ECHO                                                     '1%0A'
    4     2        YIELD                                            $1      'yield1'
          3        ASSIGN                                                   !0, $1
    5     4        ECHO                                                     '2%0A'
    6     5        INIT_FCALL                                               'var_dump'
          6        SEND_VAR                                                 !0
          7        DO_ICALL                                                 
    7     8        ECHO                                                     '3%0A'
    8     9        YIELD                                            $4      'yield2'
         10        ASSIGN                                                   !0, $4
    9    11        ECHO                                                     '4%0A'
   10    12        INIT_FCALL                                               'var_dump'
         13        SEND_VAR                                                 !0
         14        DO_ICALL                                                 
   11    15      > GENERATOR_RETURN                                         

End of function gen

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
159.86 ms | 1399 KiB | 16 Q