3v4l.org

run code in 300+ PHP versions simultaneously
<?php namespace GeneratorExample; class Pipeline { protected $generators = []; function __construct() { foreach (func_get_args() as $g) { $this->add($g); } } function add(callable $generator) { $this->generators[] = $generator; return $this; } function __invoke() { $inputs = func_get_args(); foreach ($this->generators as $g) { $generator = call_user_func_array($g, $inputs); $inputs = [$generator]; } return $generator; } } $uppercase = function(\Traversable $in) { foreach ($in as $word) { yield strtoupper($word); } }; $reverse = function(\Traversable $in) { foreach ($in as $word) { yield strrev($word); } }; $println = function(\Traversable $in) { foreach ($in as $line) { echo "$line\n"; } }; $words = new \ArrayIterator(["foo", "bar", "baz"]); $p = new Pipeline($uppercase, $reverse, $println); $p($words);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9erJO
function name:  (null)
number of ops:  20
compiled vars:  !0 = $uppercase, !1 = $reverse, !2 = $println, !3 = $words, !4 = $p
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   DECLARE_LAMBDA_FUNCTION                                  '%00generatorexample%5C%7Bclosure%7D%2Fin%2F9erJO%3A35%240'
          1        ASSIGN                                                   !0, ~5
   41     2        DECLARE_LAMBDA_FUNCTION                                  '%00generatorexample%5C%7Bclosure%7D%2Fin%2F9erJO%3A41%241'
          3        ASSIGN                                                   !1, ~7
   47     4        DECLARE_LAMBDA_FUNCTION                                  '%00generatorexample%5C%7Bclosure%7D%2Fin%2F9erJO%3A47%242'
          5        ASSIGN                                                   !2, ~9
   53     6        NEW                                              $11     'ArrayIterator'
          7        SEND_VAL_EX                                              <array>
          8        DO_FCALL                                      0          
          9        ASSIGN                                                   !3, $11
   55    10        NEW                                              $14     'GeneratorExample%5CPipeline'
         11        SEND_VAR_EX                                              !0
         12        SEND_VAR_EX                                              !1
         13        SEND_VAR_EX                                              !2
         14        DO_FCALL                                      0          
         15        ASSIGN                                                   !4, $14
   56    16        INIT_DYNAMIC_CALL                                        !4
         17        SEND_VAR_EX                                              !3
         18        DO_FCALL                                      0          
         19      > RETURN                                                   1

Function %00generatorexample%5C%7Bclosure%7D%2Fin%2F9erJO%3A35%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/9erJO
function name:  GeneratorExample\{closure}
number of ops:  11
compiled vars:  !0 = $in, !1 = $word
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   RECV                                             !0      
          1        GENERATOR_CREATE                                         
   36     2      > FE_RESET_R                                       $2      !0, ->9
          3    > > FE_FETCH_R                                               $2, !1, ->9
   37     4    >   INIT_NS_FCALL_BY_NAME                                    'GeneratorExample%5Cstrtoupper'
          5        SEND_VAR_EX                                              !1
          6        DO_FCALL                                      0  $3      
          7        YIELD                                                    $3
   36     8      > JMP                                                      ->3
          9    >   FE_FREE                                                  $2
   39    10      > GENERATOR_RETURN                                         

End of function %00generatorexample%5C%7Bclosure%7D%2Fin%2F9erJO%3A35%240

Function %00generatorexample%5C%7Bclosure%7D%2Fin%2F9erJO%3A41%241:
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/9erJO
function name:  GeneratorExample\{closure}
number of ops:  11
compiled vars:  !0 = $in, !1 = $word
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   41     0  E >   RECV                                             !0      
          1        GENERATOR_CREATE                                         
   42     2      > FE_RESET_R                                       $2      !0, ->9
          3    > > FE_FETCH_R                                               $2, !1, ->9
   43     4    >   INIT_NS_FCALL_BY_NAME                                    'GeneratorExample%5Cstrrev'
          5        SEND_VAR_EX                                              !1
          6        DO_FCALL                                      0  $3      
          7        YIELD                                                    $3
   42     8      > JMP                                                      ->3
          9    >   FE_FREE                                                  $2
   45    10      > GENERATOR_RETURN                                         

End of function %00generatorexample%5C%7Bclosure%7D%2Fin%2F9erJO%3A41%241

Function %00generatorexample%5C%7Bclosure%7D%2Fin%2F9erJO%3A47%242:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 7
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 7
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
filename:       /in/9erJO
function name:  GeneratorExample\{closure}
number of ops:  9
compiled vars:  !0 = $in, !1 = $line
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   47     0  E >   RECV                                             !0      
   48     1      > FE_RESET_R                                       $2      !0, ->7
          2    > > FE_FETCH_R                                               $2, !1, ->7
   49     3    >   NOP                                                      
          4        FAST_CONCAT                                      ~3      !1, '%0A'
          5        ECHO                                                     ~3
   48     6      > JMP                                                      ->2
          7    >   FE_FREE                                                  $2
   51     8      > RETURN                                                   null

End of function %00generatorexample%5C%7Bclosure%7D%2Fin%2F9erJO%3A47%242

Class GeneratorExample\Pipeline:
Function __construct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 8
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 8
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
filename:       /in/9erJO
function name:  __construct
number of ops:  10
compiled vars:  !0 = $g
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   INIT_NS_FCALL_BY_NAME                                    'GeneratorExample%5Cfunc_get_args'
          1        DO_FCALL                                      0  $1      
          2      > FE_RESET_R                                       $2      $1, ->8
          3    > > FE_FETCH_R                                               $2, !0, ->8
   12     4    >   INIT_METHOD_CALL                                         'add'
          5        SEND_VAR_EX                                              !0
          6        DO_FCALL                                      0          
   11     7      > JMP                                                      ->3
          8    >   FE_FREE                                                  $2
   14     9      > RETURN                                                   null

End of function __construct

Function add:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9erJO
function name:  add
number of ops:  7
compiled vars:  !0 = $generator
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   RECV                                             !0      
   18     1        FETCH_OBJ_W                                      $1      'generators'
          2        ASSIGN_DIM                                               $1
          3        OP_DATA                                                  !0
   19     4        FETCH_THIS                                       ~3      
          5      > RETURN                                                   ~3
   20     6*     > RETURN                                                   null

End of function add

Function __invoke:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 14
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 14
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
filename:       /in/9erJO
function name:  __invoke
number of ops:  17
compiled vars:  !0 = $inputs, !1 = $g, !2 = $generator
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   INIT_NS_FCALL_BY_NAME                                    'GeneratorExample%5Cfunc_get_args'
          1        DO_FCALL                                      0  $3      
          2        ASSIGN                                                   !0, $3
   26     3        FETCH_OBJ_R                                      ~5      'generators'
          4      > FE_RESET_R                                       $6      ~5, ->14
          5    > > FE_FETCH_R                                               $6, !1, ->14
   27     6    >   INIT_NS_FCALL_BY_NAME                                    'GeneratorExample%5Ccall_user_func_array'
          7        SEND_VAR_EX                                              !1
          8        SEND_VAR_EX                                              !0
          9        DO_FCALL                                      0  $7      
         10        ASSIGN                                                   !2, $7
   28    11        INIT_ARRAY                                       ~9      !2
         12        ASSIGN                                                   !0, ~9
   26    13      > JMP                                                      ->5
         14    >   FE_FREE                                                  $6
   31    15      > RETURN                                                   !2
   32    16*     > RETURN                                                   null

End of function __invoke

End of class GeneratorExample\Pipeline.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
155.73 ms | 1404 KiB | 21 Q