3v4l.org

run code in 300+ PHP versions simultaneously
<?php namespace GeneratorExample; function pipe() { $generators = func_get_args(); return function() use ($generators) { $inputs = func_get_args(); foreach ($generators as $g) { $generator = call_user_func_array($g, $inputs); $inputs = [$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 = pipe($uppercase, $reverse, $println); $p($words);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/4VIpi
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
-------------------------------------------------------------------------------------
   19     0  E >   DECLARE_LAMBDA_FUNCTION                                  '%00generatorexample%5C%7Bclosure%7D%2Fin%2F4VIpi%3A19%241'
          1        ASSIGN                                                   !0, ~5
   25     2        DECLARE_LAMBDA_FUNCTION                                  '%00generatorexample%5C%7Bclosure%7D%2Fin%2F4VIpi%3A25%242'
          3        ASSIGN                                                   !1, ~7
   31     4        DECLARE_LAMBDA_FUNCTION                                  '%00generatorexample%5C%7Bclosure%7D%2Fin%2F4VIpi%3A31%243'
          5        ASSIGN                                                   !2, ~9
   37     6        NEW                                              $11     'ArrayIterator'
          7        SEND_VAL_EX                                              <array>
          8        DO_FCALL                                      0          
          9        ASSIGN                                                   !3, $11
   39    10        INIT_NS_FCALL_BY_NAME                                    'GeneratorExample%5Cpipe'
         11        SEND_VAR_EX                                              !0
         12        SEND_VAR_EX                                              !1
         13        SEND_VAR_EX                                              !2
         14        DO_FCALL                                      0  $14     
         15        ASSIGN                                                   !4, $14
   40    16        INIT_DYNAMIC_CALL                                        !4
         17        SEND_VAR_EX                                              !3
         18        DO_FCALL                                      0          
         19      > RETURN                                                   1

Function generatorexample%5Cpipe:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/4VIpi
function name:  GeneratorExample\pipe
number of ops:  7
compiled vars:  !0 = $generators
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   INIT_NS_FCALL_BY_NAME                                    'GeneratorExample%5Cfunc_get_args'
          1        DO_FCALL                                      0  $1      
          2        ASSIGN                                                   !0, $1
    9     3        DECLARE_LAMBDA_FUNCTION                                  '%00generatorexample%5C%7Bclosure%7D%2Fin%2F4VIpi%3A9%240'
          4        BIND_LEXICAL                                             ~3, !0
   16     5      > RETURN                                                   ~3
   17     6*     > RETURN                                                   null

End of function generatorexample%5Cpipe

Function %00generatorexample%5C%7Bclosure%7D%2Fin%2F4VIpi%3A9%240:
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/4VIpi
function name:  GeneratorExample\{closure}
number of ops:  16
compiled vars:  !0 = $generators, !1 = $inputs, !2 = $g, !3 = $generator
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   BIND_STATIC                                              !0
   10     1        INIT_NS_FCALL_BY_NAME                                    'GeneratorExample%5Cfunc_get_args'
          2        DO_FCALL                                      0  $4      
          3        ASSIGN                                                   !1, $4
   12     4      > FE_RESET_R                                       $6      !0, ->14
          5    > > FE_FETCH_R                                               $6, !2, ->14
   13     6    >   INIT_NS_FCALL_BY_NAME                                    'GeneratorExample%5Ccall_user_func_array'
          7        SEND_VAR_EX                                              !2
          8        SEND_VAR_EX                                              !1
          9        DO_FCALL                                      0  $7      
         10        ASSIGN                                                   !3, $7
   14    11        INIT_ARRAY                                       ~9      !3
         12        ASSIGN                                                   !1, ~9
   12    13      > JMP                                                      ->5
         14    >   FE_FREE                                                  $6
   16    15      > RETURN                                                   null

End of function %00generatorexample%5C%7Bclosure%7D%2Fin%2F4VIpi%3A9%240

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

End of function %00generatorexample%5C%7Bclosure%7D%2Fin%2F4VIpi%3A19%241

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

End of function %00generatorexample%5C%7Bclosure%7D%2Fin%2F4VIpi%3A25%242

Function %00generatorexample%5C%7Bclosure%7D%2Fin%2F4VIpi%3A31%243:
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/4VIpi
function name:  GeneratorExample\{closure}
number of ops:  9
compiled vars:  !0 = $in, !1 = $line
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   RECV                                             !0      
   32     1      > FE_RESET_R                                       $2      !0, ->7
          2    > > FE_FETCH_R                                               $2, !1, ->7
   33     3    >   NOP                                                      
          4        FAST_CONCAT                                      ~3      !1, '%0A'
          5        ECHO                                                     ~3
   32     6      > JMP                                                      ->2
          7    >   FE_FREE                                                  $2
   35     8      > RETURN                                                   null

End of function %00generatorexample%5C%7Bclosure%7D%2Fin%2F4VIpi%3A31%243

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
156.69 ms | 1407 KiB | 22 Q