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 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(upperCaseStringFilter()) ->pipe(debugPrintFilter()) ->pipe(fooFilter()); foreach ($p as $val) { var_dump("Output", $val); }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 26, Position 2 = 32
Branch analysis from position: 26
2 jumps found. (Code = 78) Position 1 = 27, Position 2 = 32
Branch analysis from position: 27
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
Branch analysis from position: 32
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 32
filename:       /in/XKWjd
function name:  (null)
number of ops:  34
compiled vars:  !0 = $p, !1 = $val
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   DECLARE_CLASS                                            'filterpipeline'
   63     1        NEW                                              $2      'FilterPipeline'
          2        DO_FCALL                                      0          
   64     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      
   65     9        INIT_METHOD_CALL                                         $6, 'pipe'
         10        INIT_FCALL                                               'uppercasestringfilter'
         11        DO_FCALL                                      0  $7      
         12        SEND_VAR_NO_REF_EX                                       $7
         13        DO_FCALL                                      0  $8      
   66    14        INIT_METHOD_CALL                                         $8, 'pipe'
         15        INIT_FCALL                                               'debugprintfilter'
         16        DO_FCALL                                      0  $9      
         17        SEND_VAR_NO_REF_EX                                       $9
         18        DO_FCALL                                      0  $10     
   67    19        INIT_METHOD_CALL                                         $10, 'pipe'
         20        INIT_FCALL                                               'foofilter'
         21        DO_FCALL                                      0  $11     
         22        SEND_VAR_NO_REF_EX                                       $11
         23        DO_FCALL                                      0  $12     
   63    24        ASSIGN                                                   !0, $12
   69    25      > FE_RESET_R                                       $14     !0, ->32
         26    > > FE_FETCH_R                                               $14, !1, ->32
   70    27    >   INIT_FCALL                                               'var_dump'
         28        SEND_VAL                                                 'Output'
         29        SEND_VAR                                                 !1
         30        DO_ICALL                                                 
   69    31      > JMP                                                      ->26
         32    >   FE_FREE                                                  $14
   71    33      > RETURN                                                   1

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

End of function debugprintfilter

Function %00%7Bclosure%7D%2Fin%2FXKWjd%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/XKWjd
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%2FXKWjd%3A5%240

Function foofilter:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/XKWjd
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%2FXKWjd%3A15%241'
   19     1      > RETURN                                                   ~0
   20     2*     > RETURN                                                   null

End of function foofilter

Function %00%7Bclosure%7D%2Fin%2FXKWjd%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/XKWjd
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%2FXKWjd%3A15%241

Function uppercasestringfilter:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/XKWjd
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%2FXKWjd%3A24%242'
   28     1      > RETURN                                                   ~0
   29     2*     > RETURN                                                   null

End of function uppercasestringfilter

Function %00%7Bclosure%7D%2Fin%2FXKWjd%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/XKWjd
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%2FXKWjd%3A24%242

Class FilterPipeline:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/XKWjd
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/XKWjd
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/XKWjd
function name:  pipe
number of ops:  9
compiled vars:  !0 = $filter
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   45     0  E >   RECV                                             !0      
   47     1        INIT_FCALL                                               'array_push'
          2        FETCH_OBJ_W                                      $1      'filters'
          3        SEND_REF                                                 $1
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                                 
   48     6        FETCH_THIS                                       ~3      
          7      > RETURN                                                   ~3
   49     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/XKWjd
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

End of class FilterPipeline.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
148.73 ms | 1411 KiB | 22 Q