3v4l.org

run code in 300+ PHP versions simultaneously
<?php 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); } // 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))); print_r(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/7AgCS
function name:  (null)
number of ops:  16
compiled vars:  !0 = $source
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   DECLARE_CLASS                                            'mapiterator'
   43     1        NEW                                              $1      'ArrayIterator'
          2        SEND_VAL_EX                                              <array>
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !0, $1
   46     5        INIT_FCALL                                               'print_r'
          6        INIT_FCALL                                               'iterator_to_array'
          7        INIT_FCALL_BY_NAME                                       'gen_map'
          8        SEND_VAL_EX                                              'times_two'
          9        SEND_VAR_EX                                              !0
         10        DO_FCALL                                      0  $4      
         11        SEND_VAR                                                 $4
         12        DO_ICALL                                         $5      
         13        SEND_VAR                                                 $5
         14        DO_ICALL                                                 
         15      > RETURN                                                   1

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

End of function iter_map

Function times_two:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/7AgCS
function name:  times_two
number of ops:  4
compiled vars:  !0 = $x
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   39     0  E >   RECV                                             !0      
   40     1        MUL                                              ~1      !0, 2
          2      > RETURN                                                   ~1
   41     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/7AgCS
function name:  __construct
number of ops:  7
compiled vars:  !0 = $f, !1 = $inner
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    8     2        ASSIGN_OBJ                                               'f'
          3        OP_DATA                                                  !0
    9     4        ASSIGN_OBJ                                               'inner'
          5        OP_DATA                                                  !1
   10     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/7AgCS
function name:  rewind
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   FETCH_OBJ_R                                      ~0      'inner'
          1        INIT_METHOD_CALL                                         ~0, 'rewind'
          2        DO_FCALL                                      0  $1      
          3      > RETURN                                                   $1
   14     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/7AgCS
function name:  current
number of ops:  9
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     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
   18     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/7AgCS
function name:  key
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   FETCH_OBJ_R                                      ~0      'inner'
          1        INIT_METHOD_CALL                                         ~0, 'key'
          2        DO_FCALL                                      0  $1      
          3      > RETURN                                                   $1
   22     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/7AgCS
function name:  next
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   FETCH_OBJ_R                                      ~0      'inner'
          1        INIT_METHOD_CALL                                         ~0, 'next'
          2        DO_FCALL                                      0  $1      
          3      > RETURN                                                   $1
   26     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/7AgCS
function name:  valid
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   FETCH_OBJ_R                                      ~0      'inner'
          1        INIT_METHOD_CALL                                         ~0, 'valid'
          2        DO_FCALL                                      0  $1      
          3      > RETURN                                                   $1
   30     4*     > RETURN                                                   null

End of function valid

End of class MapIterator.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
155.44 ms | 1404 KiB | 17 Q