3v4l.org

run code in 300+ PHP versions simultaneously
<?php function gen_map($f, $iter) { foreach ($iter as $k => $v) { yield $k => $f($v); } } // example: function times_two($x) { return $x * 2; } $source = new ArrayIterator([0, 1, 2, 3, 4, 5, 6]); //var_dump(iterator_to_array(iter_map('times_two', $source))); var_dump(iterator_to_array(gen_map('times_two', $source)));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/XpdY4
function name:  (null)
number of ops:  15
compiled vars:  !0 = $source
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   NEW                                              $1      'ArrayIterator'
          1        SEND_VAL_EX                                              <array>
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $1
   18     4        INIT_FCALL                                               'var_dump'
          5        INIT_FCALL                                               'iterator_to_array'
          6        INIT_FCALL                                               'gen_map'
          7        SEND_VAL                                                 'times_two'
          8        SEND_VAR                                                 !0
          9        DO_FCALL                                      0  $4      
         10        SEND_VAR                                                 $4
         11        DO_ICALL                                         $5      
         12        SEND_VAR                                                 $5
         13        DO_ICALL                                                 
         14      > RETURN                                                   1

Function gen_map:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 11
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 11
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 11
1 jumps found. (Code = 161) Position 1 = -2
Branch analysis from position: 11
filename:       /in/XpdY4
function name:  gen_map
number of ops:  13
compiled vars:  !0 = $f, !1 = $iter, !2 = $v, !3 = $k
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        GENERATOR_CREATE                                         
    4     3      > FE_RESET_R                                       $4      !1, ->11
          4    > > FE_FETCH_R                                       ~5      $4, !2, ->11
          5    >   ASSIGN                                                   !3, ~5
    5     6        INIT_DYNAMIC_CALL                                        !0
          7        SEND_VAR_EX                                              !2
          8        DO_FCALL                                      0  $7      
          9        YIELD                                                    $7, !3
    4    10      > JMP                                                      ->4
         11    >   FE_FREE                                                  $4
    7    12      > GENERATOR_RETURN                                         

End of function gen_map

Function times_two:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/XpdY4
function name:  times_two
number of ops:  4
compiled vars:  !0 = $x
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   RECV                                             !0      
   12     1        MUL                                              ~1      !0, 2
          2      > RETURN                                                   ~1
   13     3*     > RETURN                                                   null

End of function times_two

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
151.13 ms | 1403 KiB | 18 Q