3v4l.org

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

Function generatorexample%5Cuppercase:
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/GucMi
function name:  GeneratorExample\uppercase
number of ops:  11
compiled vars:  !0 = $in, !1 = $word
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   RECV                                             !0      
          1        GENERATOR_CREATE                                         
   34     2      > FE_RESET_R                                       $2      !0, ->9
          3    > > FE_FETCH_R                                               $2, !1, ->9
   35     4    >   INIT_NS_FCALL_BY_NAME                                    'GeneratorExample%5Cstrtoupper'
          5        SEND_VAR_EX                                              !1
          6        DO_FCALL                                      0  $3      
          7        YIELD                                                    $3
   34     8      > JMP                                                      ->3
          9    >   FE_FREE                                                  $2
   37    10      > GENERATOR_RETURN                                         

End of function generatorexample%5Cuppercase

Function generatorexample%5Creverse:
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/GucMi
function name:  GeneratorExample\reverse
number of ops:  11
compiled vars:  !0 = $in, !1 = $word
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   39     0  E >   RECV                                             !0      
          1        GENERATOR_CREATE                                         
   41     2      > FE_RESET_R                                       $2      !0, ->9
          3    > > FE_FETCH_R                                               $2, !1, ->9
   42     4    >   INIT_NS_FCALL_BY_NAME                                    'GeneratorExample%5Cstrrev'
          5        SEND_VAR_EX                                              !1
          6        DO_FCALL                                      0  $3      
          7        YIELD                                                    $3
   41     8      > JMP                                                      ->3
          9    >   FE_FREE                                                  $2
   44    10      > GENERATOR_RETURN                                         

End of function generatorexample%5Creverse

Function generatorexample%5Ceach_println:
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/GucMi
function name:  GeneratorExample\each_println
number of ops:  9
compiled vars:  !0 = $in, !1 = $line
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   46     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 generatorexample%5Ceach_println

Class GeneratorExample\Pipeline:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/GucMi
function name:  __construct
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E > > 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/GucMi
function name:  add
number of ops:  7
compiled vars:  !0 = $generator
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   RECV                                             !0      
   15     1        FETCH_OBJ_W                                      $1      'generators'
          2        ASSIGN_DIM                                               $1
          3        OP_DATA                                                  !0
   16     4        FETCH_THIS                                       ~3      
          5      > RETURN                                                   ~3
   17     6*     > RETURN                                                   null

End of function add

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

End of function resolve

End of class GeneratorExample\Pipeline.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
155.4 ms | 1404 KiB | 23 Q