3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Route { private $method, $path, $handler; public function __construct($method, $path, $handler) { $this->method = $method; $this->path = $path; $this->handler = $handler; } public function prepend($path) { $this->path = $path . $this->path; return $this; } } function route($method, $path, $handler) { return new Route($method, $path, $handler); } function group($path, $function) { foreach ($function() as $route) { yield $route->prepend($path); } } function get_routes() { $handler = 'doSomething'; yield route('GET', '/', $handler); yield route('GET', '/foo', $handler); yield from group('/bar', function () { yield route('GET', '/hello ', $handler); yield route('GET', '/world', $handler); }); } foreach (get_routes() as $route) { var_dump($route); }
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/FONBK
function name:  (null)
number of ops:  10
compiled vars:  !0 = $route
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   46     0  E >   INIT_FCALL                                               'get_routes'
          1        DO_FCALL                                      0  $1      
          2      > FE_RESET_R                                       $2      $1, ->8
          3    > > FE_FETCH_R                                               $2, !0, ->8
   47     4    >   INIT_FCALL                                               'var_dump'
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                                 
   46     7      > JMP                                                      ->3
          8    >   FE_FREE                                                  $2
   48     9      > RETURN                                                   1

Function route:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/FONBK
function name:  route
number of ops:  10
compiled vars:  !0 = $method, !1 = $path, !2 = $handler
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   25     3        NEW                                              $3      'Route'
          4        SEND_VAR_EX                                              !0
          5        SEND_VAR_EX                                              !1
          6        SEND_VAR_EX                                              !2
          7        DO_FCALL                                      0          
          8      > RETURN                                                   $3
   26     9*     > RETURN                                                   null

End of function route

Function group:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 6, Position 2 = 12
Branch analysis from position: 6
2 jumps found. (Code = 78) Position 1 = 7, Position 2 = 12
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 12
1 jumps found. (Code = 161) Position 1 = -2
Branch analysis from position: 12
filename:       /in/FONBK
function name:  group
number of ops:  14
compiled vars:  !0 = $path, !1 = $function, !2 = $route
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        GENERATOR_CREATE                                         
   30     3        INIT_DYNAMIC_CALL                                        !1
          4        DO_FCALL                                      0  $3      
          5      > FE_RESET_R                                       $4      $3, ->12
          6    > > FE_FETCH_R                                               $4, !2, ->12
   31     7    >   INIT_METHOD_CALL                                         !2, 'prepend'
          8        SEND_VAR_EX                                              !0
          9        DO_FCALL                                      0  $5      
         10        YIELD                                                    $5
   30    11      > JMP                                                      ->6
         12    >   FE_FREE                                                  $4
   33    13      > GENERATOR_RETURN                                         

End of function group

Function get_routes:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 161) Position 1 = -2
filename:       /in/FONBK
function name:  get_routes
number of ops:  22
compiled vars:  !0 = $handler
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   GENERATOR_CREATE                                         
   37     1        ASSIGN                                                   !0, 'doSomething'
   38     2        INIT_FCALL                                               'route'
          3        SEND_VAL                                                 'GET'
          4        SEND_VAL                                                 '%2F'
          5        SEND_VAR                                                 !0
          6        DO_FCALL                                      0  $2      
          7        YIELD                                                    $2
   39     8        INIT_FCALL                                               'route'
          9        SEND_VAL                                                 'GET'
         10        SEND_VAL                                                 '%2Ffoo'
         11        SEND_VAR                                                 !0
         12        DO_FCALL                                      0  $4      
         13        YIELD                                                    $4
   40    14        INIT_FCALL                                               'group'
         15        SEND_VAL                                                 '%2Fbar'
         16        DECLARE_LAMBDA_FUNCTION                          ~6      [0]
   43    17        SEND_VAL                                                 ~6
   40    18        DO_FCALL                                      0  $7      
   43    19        YIELD_FROM                                       ~8      $7
         20        FREE                                                     ~8
   44    21      > GENERATOR_RETURN                                         


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 161) Position 1 = -2
filename:       /in/FONBK
function name:  {closure}
number of ops:  14
compiled vars:  !0 = $handler
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   40     0  E >   GENERATOR_CREATE                                         
   41     1        INIT_FCALL                                               'route'
          2        SEND_VAL                                                 'GET'
          3        SEND_VAL                                                 '%2Fhello+'
          4        SEND_VAR                                                 !0
          5        DO_FCALL                                      0  $1      
          6        YIELD                                                    $1
   42     7        INIT_FCALL                                               'route'
          8        SEND_VAL                                                 'GET'
          9        SEND_VAL                                                 '%2Fworld'
         10        SEND_VAR                                                 !0
         11        DO_FCALL                                      0  $3      
         12        YIELD                                                    $3
   43    13      > GENERATOR_RETURN                                         

End of Dynamic Function 0

End of function get_routes

Class Route:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/FONBK
function name:  __construct
number of ops:  10
compiled vars:  !0 = $method, !1 = $path, !2 = $handler
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   10     3        ASSIGN_OBJ                                               'method'
          4        OP_DATA                                                  !0
   11     5        ASSIGN_OBJ                                               'path'
          6        OP_DATA                                                  !1
   12     7        ASSIGN_OBJ                                               'handler'
          8        OP_DATA                                                  !2
   13     9      > RETURN                                                   null

End of function __construct

Function prepend:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/FONBK
function name:  prepend
number of ops:  8
compiled vars:  !0 = $path
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   RECV                                             !0      
   17     1        FETCH_OBJ_R                                      ~2      'path'
          2        CONCAT                                           ~3      !0, ~2
          3        ASSIGN_OBJ                                               'path'
          4        OP_DATA                                                  ~3
   18     5        FETCH_THIS                                       ~4      
          6      > RETURN                                                   ~4
   19     7*     > RETURN                                                   null

End of function prepend

End of class Route.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
143.62 ms | 1011 KiB | 20 Q