3v4l.org

run code in 300+ PHP versions simultaneously
<?php trait OuterIteratorTrait { private $inner; /** * @return bool */ function isEmpty() { $iterator = clone $this->inner; $iterator->rewind(); return !$iterator->valid(); } function rewind() { $this->inner->rewind(); } function valid() { return $this->inner->valid(); } function next() { $this->inner->next(); } function current() { return $this->inner->current(); } function key() { return $this->inner->key(); } } class MappingIterator implements Iterator { use OuterIteratorTrait; private $mapper; function __construct(\Iterator $i, callable $f) { $this->inner = $i; $this->mapper = $f; } function current() { return call_user_func($this->mapper, $this->inner->current(), $this->key()); } } $i = new ArrayIterator(array(0, 2, 4)); $mapper = new MappingIterator($i, function($val){ return 2 * $val;}); var_dump(iterator_to_array($mapper));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/F29gc
function name:  (null)
number of ops:  18
compiled vars:  !0 = $i, !1 = $mapper
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   45     0  E >   DECLARE_CLASS                                            'mappingiterator'
   64     1        NEW                                              $2      'ArrayIterator'
          2        SEND_VAL_EX                                              <array>
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !0, $2
   65     5        NEW                                              $5      'MappingIterator'
          6        SEND_VAR_EX                                              !0
          7        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FF29gc%3A65%241'
          8        SEND_VAL_EX                                              ~6
          9        DO_FCALL                                      0          
         10        ASSIGN                                                   !1, $5
   67    11        INIT_FCALL                                               'var_dump'
         12        INIT_FCALL                                               'iterator_to_array'
         13        SEND_VAR                                                 !1
         14        DO_ICALL                                         $9      
         15        SEND_VAR                                                 $9
         16        DO_ICALL                                                 
         17      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FF29gc%3A65%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/F29gc
function name:  {closure}
number of ops:  4
compiled vars:  !0 = $val
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   65     0  E >   RECV                                             !0      
          1        MUL                                              ~1      !0, 2
          2      > RETURN                                                   ~1
          3*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FF29gc%3A65%241

Class OuterIteratorTrait:
Function isempty:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/F29gc
function name:  isEmpty
number of ops:  10
compiled vars:  !0 = $iterator
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   FETCH_OBJ_R                                      ~1      'inner'
          1        CLONE                                            ~2      ~1
          2        ASSIGN                                                   !0, ~2
   13     3        INIT_METHOD_CALL                                         !0, 'rewind'
          4        DO_FCALL                                      0          
   14     5        INIT_METHOD_CALL                                         !0, 'valid'
          6        DO_FCALL                                      0  $5      
          7        BOOL_NOT                                         ~6      $5
          8      > RETURN                                                   ~6
   15     9*     > RETURN                                                   null

End of function isempty

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

End of function rewind

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

End of function valid

Function next:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/F29gc
function name:  next
number of ops:  4
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, 'next'
          2        DO_FCALL                                      0          
   30     3      > RETURN                                                   null

End of function next

Function current:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/F29gc
function name:  current
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   FETCH_OBJ_R                                      ~0      'inner'
          1        INIT_METHOD_CALL                                         ~0, 'current'
          2        DO_FCALL                                      0  $1      
          3      > RETURN                                                   $1
   35     4*     > 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/F29gc
function name:  key
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   39     0  E >   FETCH_OBJ_R                                      ~0      'inner'
          1        INIT_METHOD_CALL                                         ~0, 'key'
          2        DO_FCALL                                      0  $1      
          3      > RETURN                                                   $1
   40     4*     > RETURN                                                   null

End of function key

End of class OuterIteratorTrait.

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

End of function __construct

Function current:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/F29gc
function name:  current
number of ops:  12
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   59     0  E >   FETCH_OBJ_R                                      ~0      'mapper'
          1        INIT_USER_CALL                                2          '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        INIT_METHOD_CALL                                         'key'
          7        DO_FCALL                                      0  $3      
          8        SEND_USER                                                $3
          9        DO_FCALL                                      0  $4      
         10      > RETURN                                                   $4
   60    11*     > RETURN                                                   null

End of function current

End of class MappingIterator.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
153.4 ms | 1404 KiB | 17 Q