3v4l.org

run code in 300+ PHP versions simultaneously
<?php // iterator impl: class MapIterator implements Iterator { private $f; private $inner; public function __construct($f, $inner) { $this->f = $f; $this->inner = $inner; } function rewind() { return $this->inner->rewind(); } function current() { return call_user_func($this->f, $this->inner->current()); } function key() { return $this->inner->key(); } function next() { return $this->inner->next(); } function valid() { return $this->inner->valid(); } } function iter_map($f, $iter) { return new MapIterator($f, $iter); } // generator impl: 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/kUI8l
function name:  (null)
number of ops:  26
compiled vars:  !0 = $source
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   DECLARE_CLASS                                            'mapiterator'
   53     1        NEW                                              $1      'ArrayIterator'
          2        SEND_VAL_EX                                              <array>
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !0, $1
   55     5        INIT_FCALL                                               'var_dump'
          6        INIT_FCALL                                               'iterator_to_array'
          7        INIT_FCALL                                               'iter_map'
          8        SEND_VAL                                                 'times_two'
          9        SEND_VAR                                                 !0
         10        DO_FCALL                                      0  $4      
         11        SEND_VAR                                                 $4
         12        DO_ICALL                                         $5      
         13        SEND_VAR                                                 $5
         14        DO_ICALL                                                 
   56    15        INIT_FCALL                                               'var_dump'
         16        INIT_FCALL                                               'iterator_to_array'
         17        INIT_FCALL                                               'gen_map'
         18        SEND_VAL                                                 'times_two'
         19        SEND_VAR                                                 !0
         20        DO_FCALL                                      0  $7      
         21        SEND_VAR                                                 $7
         22        DO_ICALL                                         $8      
         23        SEND_VAR                                                 $8
         24        DO_ICALL                                                 
         25      > RETURN                                                   1

Function iter_map:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/kUI8l
function name:  iter_map
number of ops:  8
compiled vars:  !0 = $f, !1 = $iter
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   36     2        NEW                                              $2      'MapIterator'
          3        SEND_VAR_EX                                              !0
          4        SEND_VAR_EX                                              !1
          5        DO_FCALL                                      0          
          6      > RETURN                                                   $2
   37     7*     > RETURN                                                   null

End of function iter_map

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/kUI8l
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
-------------------------------------------------------------------------------------
   41     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        GENERATOR_CREATE                                         
   42     3      > FE_RESET_R                                       $4      !1, ->11
          4    > > FE_FETCH_R                                       ~5      $4, !2, ->11
          5    >   ASSIGN                                                   !3, ~5
   43     6        INIT_DYNAMIC_CALL                                        !0
          7        SEND_VAR_EX                                              !2
          8        DO_FCALL                                      0  $7      
          9        YIELD                                                    $7, !3
   42    10      > JMP                                                      ->4
         11    >   FE_FREE                                                  $4
   45    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/kUI8l
function name:  times_two
number of ops:  4
compiled vars:  !0 = $x
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   49     0  E >   RECV                                             !0      
   50     1        MUL                                              ~1      !0, 2
          2      > RETURN                                                   ~1
   51     3*     > RETURN                                                   null

End of function times_two

Class MapIterator:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/kUI8l
function name:  __construct
number of ops:  7
compiled vars:  !0 = $f, !1 = $inner
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   10     2        ASSIGN_OBJ                                               'f'
          3        OP_DATA                                                  !0
   11     4        ASSIGN_OBJ                                               'inner'
          5        OP_DATA                                                  !1
   12     6      > RETURN                                                   null

End of function __construct

Function rewind:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/kUI8l
function name:  rewind
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   FETCH_OBJ_R                                      ~0      'inner'
          1        INIT_METHOD_CALL                                         ~0, 'rewind'
          2        DO_FCALL                                      0  $1      
          3      > RETURN                                                   $1
   16     4*     > RETURN                                                   null

End of function rewind

Function current:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/kUI8l
function name:  current
number of ops:  9
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   FETCH_OBJ_R                                      ~0      'f'
          1        INIT_USER_CALL                                1          'call_user_func', ~0
          2        FETCH_OBJ_R                                      ~1      'inner'
          3        INIT_METHOD_CALL                                         ~1, 'current'
          4        DO_FCALL                                      0  $2      
          5        SEND_USER                                                $2
          6        DO_FCALL                                      0  $3      
          7      > RETURN                                                   $3
   20     8*     > RETURN                                                   null

End of function current

Function key:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/kUI8l
function name:  key
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   FETCH_OBJ_R                                      ~0      'inner'
          1        INIT_METHOD_CALL                                         ~0, 'key'
          2        DO_FCALL                                      0  $1      
          3      > RETURN                                                   $1
   24     4*     > RETURN                                                   null

End of function key

Function next:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/kUI8l
function name:  next
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   FETCH_OBJ_R                                      ~0      'inner'
          1        INIT_METHOD_CALL                                         ~0, 'next'
          2        DO_FCALL                                      0  $1      
          3      > RETURN                                                   $1
   28     4*     > RETURN                                                   null

End of function next

Function valid:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/kUI8l
function name:  valid
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   FETCH_OBJ_R                                      ~0      'inner'
          1        INIT_METHOD_CALL                                         ~0, 'valid'
          2        DO_FCALL                                      0  $1      
          3      > RETURN                                                   $1
   32     4*     > RETURN                                                   null

End of function valid

End of class MapIterator.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
174.18 ms | 1407 KiB | 19 Q