3v4l.org

run code in 300+ PHP versions simultaneously
<?php function gen(int $x) { $x = yield $x + 1; $x = yield $x + 2; $x = yield $x + 3; $x = yield $x + 4; } $gen = gen(5); $assertions = [ ['expect' => 6], ['send' => 1, 'expect' => 3], ['send' => 5, 'expect' => 8], ['send' => 3, 'expect' => 7], ]; foreach($assertions as $assertion) { if(!array_key_exists('send', $assertion)) { echo '(Received / Initial Assertion / Whatever) ' . $gen->current() . PHP_EOL; continue; } echo $assertion['expect'] . ' === ' . $gen->send($assertion['send']) . PHP_EOL; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 6, Position 2 = 27
Branch analysis from position: 6
2 jumps found. (Code = 78) Position 1 = 7, Position 2 = 27
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 16
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 27
filename:       /in/e9u2f
function name:  (null)
number of ops:  29
compiled vars:  !0 = $gen, !1 = $assertions, !2 = $assertion
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   INIT_FCALL                                               'gen'
          1        SEND_VAL                                                 5
          2        DO_FCALL                                      0  $3      
          3        ASSIGN                                                   !0, $3
   12     4        ASSIGN                                                   !1, <array>
   18     5      > FE_RESET_R                                       $6      !1, ->27
          6    > > FE_FETCH_R                                               $6, !2, ->27
   19     7    >   ARRAY_KEY_EXISTS                                 ~7      'send', !2
          8        BOOL_NOT                                         ~8      ~7
          9      > JMPZ                                                     ~8, ->16
   20    10    >   INIT_METHOD_CALL                                         !0, 'current'
         11        DO_FCALL                                      0  $9      
         12        CONCAT                                           ~10     '%28Received+%2F+Initial+Assertion+%2F+Whatever%29+', $9
         13        CONCAT                                           ~11     ~10, '%0A'
         14        ECHO                                                     ~11
   21    15      > JMP                                                      ->6
   23    16    >   FETCH_DIM_R                                      ~12     !2, 'expect'
         17        CONCAT                                           ~13     ~12, '+%3D%3D%3D+'
         18        INIT_METHOD_CALL                                         !0, 'send'
         19        CHECK_FUNC_ARG                                           
         20        FETCH_DIM_FUNC_ARG                               $14     !2, 'send'
         21        SEND_FUNC_ARG                                            $14
         22        DO_FCALL                                      0  $15     
         23        CONCAT                                           ~16     ~13, $15
         24        CONCAT                                           ~17     ~16, '%0A'
         25        ECHO                                                     ~17
   18    26      > JMP                                                      ->6
         27    >   FE_FREE                                                  $6
   24    28      > RETURN                                                   1

Function gen:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 161) Position 1 = -2
filename:       /in/e9u2f
function name:  gen
number of ops:  15
compiled vars:  !0 = $x
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        GENERATOR_CREATE                                         
    4     2        ADD                                              ~1      !0, 1
          3        YIELD                                            $2      ~1
          4        ASSIGN                                                   !0, $2
    5     5        ADD                                              ~4      !0, 2
          6        YIELD                                            $5      ~4
          7        ASSIGN                                                   !0, $5
    6     8        ADD                                              ~7      !0, 3
          9        YIELD                                            $8      ~7
         10        ASSIGN                                                   !0, $8
    7    11        ADD                                              ~10     !0, 4
         12        YIELD                                            $11     ~10
         13        ASSIGN                                                   !0, $11
    8    14      > GENERATOR_RETURN                                         

End of function gen

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
138.22 ms | 1003 KiB | 14 Q