3v4l.org

run code in 300+ PHP versions simultaneously
<?php function debugPrintFilter() { return function(\Traversable $input) { foreach ($input as $in) { print_r($in); yield $in; } }; } class FilterPipeline implements \IteratorAggregate { protected $filters = []; protected $src; function __construct() { } function src(\Traversable $it) { $this->src = $it; return $this; } function pipe(callable $filter) { array_push($this->filters, $filter); return $this; } function getIterator() { $it = $this->src; foreach ($this->filters as $filter) { $it = $filter($it); } return $it; } } $p = (new FilterPipeline) ->src(new \ArrayIterator(["foo", "bar", "baz"])) ->pipe(debugPrintFilter()); foreach ($p as $val) {}
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 16, Position 2 = 18
Branch analysis from position: 16
2 jumps found. (Code = 78) Position 1 = 17, Position 2 = 18
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
filename:       /in/4YQWN
function name:  (null)
number of ops:  20
compiled vars:  !0 = $p, !1 = $val
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   DECLARE_CLASS                                            'filterpipeline'
   45     1        NEW                                              $2      'FilterPipeline'
          2        DO_FCALL                                      0          
   46     3        INIT_METHOD_CALL                                         $2, 'src'
          4        NEW                                              $4      'ArrayIterator'
          5        SEND_VAL_EX                                              <array>
          6        DO_FCALL                                      0          
          7        SEND_VAR_NO_REF_EX                                       $4
          8        DO_FCALL                                      0  $6      
   47     9        INIT_METHOD_CALL                                         $6, 'pipe'
         10        INIT_FCALL                                               'debugprintfilter'
         11        DO_FCALL                                      0  $7      
         12        SEND_VAR_NO_REF_EX                                       $7
         13        DO_FCALL                                      0  $8      
   45    14        ASSIGN                                                   !0, $8
   49    15      > FE_RESET_R                                       $10     !0, ->18
         16    > > FE_FETCH_R                                               $10, !1, ->18
         17    > > JMP                                                      ->16
         18    >   FE_FREE                                                  $10
         19      > RETURN                                                   1

Function debugprintfilter:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/4YQWN
function name:  debugPrintFilter
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F4YQWN%3A5%240'
   10     1      > RETURN                                                   ~0
   11     2*     > RETURN                                                   null

End of function debugprintfilter

Function %00%7Bclosure%7D%2Fin%2F4YQWN%3A5%240:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 9
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 9
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 9
1 jumps found. (Code = 161) Position 1 = -2
Branch analysis from position: 9
filename:       /in/4YQWN
function name:  {closure}
number of ops:  11
compiled vars:  !0 = $input, !1 = $in
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
          1        GENERATOR_CREATE                                         
    6     2      > FE_RESET_R                                       $2      !0, ->9
          3    > > FE_FETCH_R                                               $2, !1, ->9
    7     4    >   INIT_FCALL                                               'print_r'
          5        SEND_VAR                                                 !1
          6        DO_ICALL                                                 
    8     7        YIELD                                                    !1
    6     8      > JMP                                                      ->3
          9    >   FE_FREE                                                  $2
   10    10      > GENERATOR_RETURN                                         

End of function %00%7Bclosure%7D%2Fin%2F4YQWN%3A5%240

Class FilterPipeline:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/4YQWN
function name:  __construct
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E > > RETURN                                                   null

End of function __construct

Function src:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/4YQWN
function name:  src
number of ops:  6
compiled vars:  !0 = $it
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   RECV                                             !0      
   23     1        ASSIGN_OBJ                                               'src'
          2        OP_DATA                                                  !0
   24     3        FETCH_THIS                                       ~2      
          4      > RETURN                                                   ~2
   25     5*     > RETURN                                                   null

End of function src

Function pipe:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/4YQWN
function name:  pipe
number of ops:  9
compiled vars:  !0 = $filter
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   RECV                                             !0      
   29     1        INIT_FCALL                                               'array_push'
          2        FETCH_OBJ_W                                      $1      'filters'
          3        SEND_REF                                                 $1
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                                 
   30     6        FETCH_THIS                                       ~3      
          7      > RETURN                                                   ~3
   31     8*     > RETURN                                                   null

End of function pipe

Function getiterator:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 10
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 10
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
filename:       /in/4YQWN
function name:  getIterator
number of ops:  13
compiled vars:  !0 = $it, !1 = $filter
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   FETCH_OBJ_R                                      ~2      'src'
          1        ASSIGN                                                   !0, ~2
   37     2        FETCH_OBJ_R                                      ~4      'filters'
          3      > FE_RESET_R                                       $5      ~4, ->10
          4    > > FE_FETCH_R                                               $5, !1, ->10
   38     5    >   INIT_DYNAMIC_CALL                                        !1
          6        SEND_VAR_EX                                              !0
          7        DO_FCALL                                      0  $6      
          8        ASSIGN                                                   !0, $6
   37     9      > JMP                                                      ->4
         10    >   FE_FREE                                                  $5
   41    11      > RETURN                                                   !0
   42    12*     > RETURN                                                   null

End of function getiterator

End of class FilterPipeline.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
166.83 ms | 1406 KiB | 18 Q