3v4l.org

run code in 300+ PHP versions simultaneously
<?php function debugPrintFilter() { return function(\Traversable $input) { foreach ($input as $in) { var_dump($in); yield $in; } }; } function fooFilter() { return function(\Traversable $input) { foreach ($input as $in) { yield "foo"; } }; } function upperCaseStringFilter() { return function(\Traversable $input) { foreach ($input as $in) { yield strtoupper($in); } }; } class Pipeline implements \IteratorAggregate { protected $filters = []; protected $src; function __construct() { } function src(\Traversable $it) { $this->src = $it; return $this; } function pipe(callable $filter) { $this->filters[] = $filter; return $this; } function getIterator() { $it = $this->src; foreach ($this->filters as $filter) { $it = $filter($it); } return $it; } function run() { foreach($this as $it) {} return $this; } } $p = (new Pipeline) ->src(new \ArrayIterator(["foo", "bar", "baz"])) ->pipe(upperCaseStringFilter()) ->pipe(debugPrintFilter()) ->pipe(fooFilter()) ->pipe(debugPrintFilter()) ->run();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Nf93P
function name:  (null)
number of ops:  33
compiled vars:  !0 = $p
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   DECLARE_CLASS                                            'pipeline'
   69     1        NEW                                              $1      'Pipeline'
          2        DO_FCALL                                      0          
   70     3        INIT_METHOD_CALL                                         $1, 'src'
          4        NEW                                              $3      'ArrayIterator'
          5        SEND_VAL_EX                                              <array>
          6        DO_FCALL                                      0          
          7        SEND_VAR_NO_REF_EX                                       $3
          8        DO_FCALL                                      0  $5      
   71     9        INIT_METHOD_CALL                                         $5, 'pipe'
         10        INIT_FCALL                                               'uppercasestringfilter'
         11        DO_FCALL                                      0  $6      
         12        SEND_VAR_NO_REF_EX                                       $6
         13        DO_FCALL                                      0  $7      
   72    14        INIT_METHOD_CALL                                         $7, 'pipe'
         15        INIT_FCALL                                               'debugprintfilter'
         16        DO_FCALL                                      0  $8      
         17        SEND_VAR_NO_REF_EX                                       $8
         18        DO_FCALL                                      0  $9      
   73    19        INIT_METHOD_CALL                                         $9, 'pipe'
         20        INIT_FCALL                                               'foofilter'
         21        DO_FCALL                                      0  $10     
         22        SEND_VAR_NO_REF_EX                                       $10
         23        DO_FCALL                                      0  $11     
   74    24        INIT_METHOD_CALL                                         $11, 'pipe'
         25        INIT_FCALL                                               'debugprintfilter'
         26        DO_FCALL                                      0  $12     
         27        SEND_VAR_NO_REF_EX                                       $12
         28        DO_FCALL                                      0  $13     
   75    29        INIT_METHOD_CALL                                         $13, 'run'
         30        DO_FCALL                                      0  $14     
   69    31        ASSIGN                                                   !0, $14
   75    32      > RETURN                                                   1

Function debugprintfilter:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Nf93P
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%2FNf93P%3A5%240'
   10     1      > RETURN                                                   ~0
   11     2*     > RETURN                                                   null

End of function debugprintfilter

Function %00%7Bclosure%7D%2Fin%2FNf93P%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/Nf93P
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                                               'var_dump'
          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%2FNf93P%3A5%240

Function foofilter:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Nf93P
function name:  fooFilter
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FNf93P%3A15%241'
   19     1      > RETURN                                                   ~0
   20     2*     > RETURN                                                   null

End of function foofilter

Function %00%7Bclosure%7D%2Fin%2FNf93P%3A15%241:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 6
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 6
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 6
1 jumps found. (Code = 161) Position 1 = -2
Branch analysis from position: 6
filename:       /in/Nf93P
function name:  {closure}
number of ops:  8
compiled vars:  !0 = $input, !1 = $in
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   RECV                                             !0      
          1        GENERATOR_CREATE                                         
   16     2      > FE_RESET_R                                       $2      !0, ->6
          3    > > FE_FETCH_R                                               $2, !1, ->6
   17     4    >   YIELD                                                    'foo'
   16     5      > JMP                                                      ->3
          6    >   FE_FREE                                                  $2
   19     7      > GENERATOR_RETURN                                         

End of function %00%7Bclosure%7D%2Fin%2FNf93P%3A15%241

Function uppercasestringfilter:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Nf93P
function name:  upperCaseStringFilter
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FNf93P%3A24%242'
   28     1      > RETURN                                                   ~0
   29     2*     > RETURN                                                   null

End of function uppercasestringfilter

Function %00%7Bclosure%7D%2Fin%2FNf93P%3A24%242:
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/Nf93P
function name:  {closure}
number of ops:  11
compiled vars:  !0 = $input, !1 = $in
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
          1        GENERATOR_CREATE                                         
   25     2      > FE_RESET_R                                       $2      !0, ->9
          3    > > FE_FETCH_R                                               $2, !1, ->9
   26     4    >   INIT_FCALL                                               'strtoupper'
          5        SEND_VAR                                                 !1
          6        DO_ICALL                                         $3      
          7        YIELD                                                    $3
   25     8      > JMP                                                      ->3
          9    >   FE_FREE                                                  $2
   28    10      > GENERATOR_RETURN                                         

End of function %00%7Bclosure%7D%2Fin%2FNf93P%3A24%242

Class Pipeline:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Nf93P
function name:  __construct
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   37     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/Nf93P
function name:  src
number of ops:  6
compiled vars:  !0 = $it
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   39     0  E >   RECV                                             !0      
   41     1        ASSIGN_OBJ                                               'src'
          2        OP_DATA                                                  !0
   42     3        FETCH_THIS                                       ~2      
          4      > RETURN                                                   ~2
   43     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/Nf93P
function name:  pipe
number of ops:  7
compiled vars:  !0 = $filter
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   45     0  E >   RECV                                             !0      
   47     1        FETCH_OBJ_W                                      $1      'filters'
          2        ASSIGN_DIM                                               $1
          3        OP_DATA                                                  !0
   48     4        FETCH_THIS                                       ~3      
          5      > RETURN                                                   ~3
   49     6*     > 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/Nf93P
function name:  getIterator
number of ops:  13
compiled vars:  !0 = $it, !1 = $filter
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   53     0  E >   FETCH_OBJ_R                                      ~2      'src'
          1        ASSIGN                                                   !0, ~2
   55     2        FETCH_OBJ_R                                      ~4      'filters'
          3      > FE_RESET_R                                       $5      ~4, ->10
          4    > > FE_FETCH_R                                               $5, !1, ->10
   56     5    >   INIT_DYNAMIC_CALL                                        !1
          6        SEND_VAR_EX                                              !0
          7        DO_FCALL                                      0  $6      
          8        ASSIGN                                                   !0, $6
   55     9      > JMP                                                      ->4
         10    >   FE_FREE                                                  $5
   59    11      > RETURN                                                   !0
   60    12*     > RETURN                                                   null

End of function getiterator

Function run:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 4
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 4
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 4
filename:       /in/Nf93P
function name:  run
number of ops:  8
compiled vars:  !0 = $it
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   64     0  E >   FETCH_THIS                                       ~1      
          1      > FE_RESET_R                                       $2      ~1, ->4
          2    > > FE_FETCH_R                                               $2, !0, ->4
          3    > > JMP                                                      ->2
          4    >   FE_FREE                                                  $2
   65     5        FETCH_THIS                                       ~3      
          6      > RETURN                                                   ~3
   66     7*     > RETURN                                                   null

End of function run

End of class Pipeline.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
163.93 ms | 1402 KiB | 21 Q