3v4l.org

run code in 300+ PHP versions simultaneously
<?php namespace GeneratorExample; class Pipeline { protected $generators; function __construct() { $this->generators = new \SplStack; } function add(callable $generator) { $this->generators->push($generator); return $this; } function resolve() { $inputs = func_get_args(); foreach ($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/S5T26
function name:  (null)
number of ops:  20
compiled vars:  !0 = $words, !1 = $p
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   54     0  E >   NEW                                              $2      'ArrayIterator'
          1        SEND_VAL_EX                                              <array>
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $2
   56     4        NEW                                              $5      'GeneratorExample%5CPipeline'
          5        DO_FCALL                                      0          
          6        ASSIGN                                                   !1, $5
   57     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          
   58    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/S5T26
function name:  GeneratorExample\uppercase
number of ops:  11
compiled vars:  !0 = $in, !1 = $word
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   RECV                                             !0      
          1        GENERATOR_CREATE                                         
   35     2      > FE_RESET_R                                       $2      !0, ->9
          3    > > FE_FETCH_R                                               $2, !1, ->9
   36     4    >   INIT_NS_FCALL_BY_NAME                                    'GeneratorExample%5Cstrtoupper'
          5        SEND_VAR_EX                                              !1
          6        DO_FCALL                                      0  $3      
          7        YIELD                                                    $3
   35     8      > JMP                                                      ->3
          9    >   FE_FREE                                                  $2
   38    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/S5T26
function name:  GeneratorExample\reverse
number of ops:  11
compiled vars:  !0 = $in, !1 = $word
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   40     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 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/S5T26
function name:  GeneratorExample\each_println
number of ops:  9
compiled vars:  !0 = $in, !1 = $line
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   47     0  E >   RECV                                             !0      
   49     1      > FE_RESET_R                                       $2      !0, ->7
          2    > > FE_FETCH_R                                               $2, !1, ->7
   50     3    >   NOP                                                      
          4        FAST_CONCAT                                      ~3      !1, '%0A'
          5        ECHO                                                     ~3
   49     6      > JMP                                                      ->2
          7    >   FE_FREE                                                  $2
   52     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/S5T26
function name:  __construct
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   NEW                                              $1      'SplStack'
          1        DO_FCALL                                      0          
          2        ASSIGN_OBJ                                               'generators'
          3        OP_DATA                                                  $1
   12     4      > 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/S5T26
function name:  add
number of ops:  8
compiled vars:  !0 = $generator
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
   16     1        FETCH_OBJ_R                                      ~1      'generators'
          2        INIT_METHOD_CALL                                         ~1, 'push'
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0          
   17     5        FETCH_THIS                                       ~3      
          6      > RETURN                                                   ~3
   18     7*     > RETURN                                                   null

End of function add

Function resolve:
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/S5T26
function name:  resolve
number of ops:  17
compiled vars:  !0 = $inputs, !1 = $g, !2 = $generator
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   INIT_NS_FCALL_BY_NAME                                    'GeneratorExample%5Cfunc_get_args'
          1        DO_FCALL                                      0  $3      
          2        ASSIGN                                                   !0, $3
   24     3        FETCH_OBJ_R                                      ~5      'generators'
          4      > FE_RESET_R                                       $6      ~5, ->14
          5    > > FE_FETCH_R                                               $6, !1, ->14
   25     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
   26    11        INIT_ARRAY                                       ~9      !2
         12        ASSIGN                                                   !0, ~9
   24    13      > JMP                                                      ->5
         14    >   FE_FREE                                                  $6
   29    15      > RETURN                                                   !2
   30    16*     > RETURN                                                   null

End of function resolve

End of class GeneratorExample\Pipeline.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
168.11 ms | 1404 KiB | 21 Q