3v4l.org

run code in 300+ PHP versions simultaneously
<?php $g = function () { $num = yield "random_number"; $str = yield "random_string"; $num2 = yield "random_number"; echo "Hey it's g, I've got: {$num}, {$str}, {$num2}\n"; }; $gen = $g(); while ($gen->valid()) { $generated = $gen->current(); echo "g is asking for {$generated}\n"; switch ($generated) { case "random_number": $gen->send(random_int(0, 1000000000)); break; case "random_string": $gen->send(bin2hex(random_bytes(16))); break; } }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 37
Branch analysis from position: 37
2 jumps found. (Code = 44) Position 1 = 40, Position 2 = 6
Branch analysis from position: 40
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
4 jumps found. (Code = 188) Position 1 = 19, Position 2 = 27, Position 3 = 37, Position 4 = 14
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 37
Branch analysis from position: 37
Branch analysis from position: 27
1 jumps found. (Code = 42) Position 1 = 37
Branch analysis from position: 37
Branch analysis from position: 37
Branch analysis from position: 14
2 jumps found. (Code = 44) Position 1 = 16, Position 2 = 19
Branch analysis from position: 16
2 jumps found. (Code = 44) Position 1 = 18, Position 2 = 27
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 37
Branch analysis from position: 37
Branch analysis from position: 27
Branch analysis from position: 19
filename:       /in/Q9i1P
function name:  (null)
number of ops:  41
compiled vars:  !0 = $g, !1 = $gen, !2 = $generated
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   DECLARE_LAMBDA_FUNCTION                          ~3      [0]
          1        ASSIGN                                                   !0, ~3
   11     2        INIT_DYNAMIC_CALL                                        !0
          3        DO_FCALL                                      0  $5      
          4        ASSIGN                                                   !1, $5
   13     5      > JMP                                                      ->37
   14     6    >   INIT_METHOD_CALL                                         !1, 'current'
          7        DO_FCALL                                      0  $7      
          8        ASSIGN                                                   !2, $7
   16     9        ROPE_INIT                                     3  ~10     'g+is+asking+for+'
         10        ROPE_ADD                                      1  ~10     ~10, !2
         11        ROPE_END                                      2  ~9      ~10, '%0A'
         12        ECHO                                                     ~9
   18    13      > SWITCH_STRING                                            !2, [ 'random_number':->19, 'random_string':->27, ], ->37
   19    14    >   IS_EQUAL                                                 !2, 'random_number'
         15      > JMPNZ                                                    ~12, ->19
   22    16    >   IS_EQUAL                                                 !2, 'random_string'
         17      > JMPNZ                                                    ~12, ->27
         18    > > JMP                                                      ->37
   20    19    >   INIT_METHOD_CALL                                         !1, 'send'
         20        INIT_FCALL                                               'random_int'
         21        SEND_VAL                                                 0
         22        SEND_VAL                                                 1000000000
         23        DO_ICALL                                         $13     
         24        SEND_VAR_NO_REF_EX                                       $13
         25        DO_FCALL                                      0          
   21    26      > JMP                                                      ->37
   23    27    >   INIT_METHOD_CALL                                         !1, 'send'
         28        INIT_FCALL                                               'bin2hex'
         29        INIT_FCALL                                               'random_bytes'
         30        SEND_VAL                                                 16
         31        DO_ICALL                                         $15     
         32        SEND_VAR                                                 $15
         33        DO_ICALL                                         $16     
         34        SEND_VAR_NO_REF_EX                                       $16
         35        DO_FCALL                                      0          
   24    36      > JMP                                                      ->37
   13    37    >   INIT_METHOD_CALL                                         !1, 'valid'
         38        DO_FCALL                                      0  $18     
         39      > JMPNZ                                                    $18, ->6
   26    40    > > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 161) Position 1 = -2
filename:       /in/Q9i1P
function name:  {closure}
number of ops:  16
compiled vars:  !0 = $num, !1 = $str, !2 = $num2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   GENERATOR_CREATE                                         
    4     1        YIELD                                            $3      'random_number'
          2        ASSIGN                                                   !0, $3
    5     3        YIELD                                            $5      'random_string'
          4        ASSIGN                                                   !1, $5
    6     5        YIELD                                            $7      'random_number'
          6        ASSIGN                                                   !2, $7
    8     7        ROPE_INIT                                     7  ~10     'Hey+it%27s+g%2C+I%27ve+got%3A+'
          8        ROPE_ADD                                      1  ~10     ~10, !0
          9        ROPE_ADD                                      2  ~10     ~10, '%2C+'
         10        ROPE_ADD                                      3  ~10     ~10, !1
         11        ROPE_ADD                                      4  ~10     ~10, '%2C+'
         12        ROPE_ADD                                      5  ~10     ~10, !2
         13        ROPE_END                                      6  ~9      ~10, '%0A'
         14        ECHO                                                     ~9
    9    15      > GENERATOR_RETURN                                         

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
158.11 ms | 1009 KiB | 16 Q