3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Configure here: $userSpecifiedPath = '/'; // ================================================================ // Don't edit below // ================================================================ $routerConfig = <<<CONFIG [/] "Controller" = "HomepageController" [404] "Controller" = "404Controller" CONFIG; class Router { private $routes; public function __construct($routes) { $this->routes = $routes; } public function getControllerFromPath($path) { if(array_key_exists($path, $this->routes) === true) { return $this->routes[$path]; } elseif(array_key_exists('404', $this->routes) === true) { return $this->routes['404']; } } } $routes = parse_ini_string($routerConfig, true); print_r($routes); $Router = new Router($routes); echo 'Using controller: ' . $Router->getControllerFromPath($userSpecifiedPath);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WRrsL
function name:  (null)
number of ops:  20
compiled vars:  !0 = $userSpecifiedPath, !1 = $routerConfig, !2 = $routes, !3 = $Router
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   ASSIGN                                                   !0, '%2F'
   14     1        ASSIGN                                                   !1, '%5B%2F%5D%0A%22Controller%22+%3D+%22HomepageController%22%0A%0A%5B404%5D%0A%22Controller%22+%3D+%22404Controller%22'
   41     2        INIT_FCALL                                               'parse_ini_string'
          3        SEND_VAR                                                 !1
          4        SEND_VAL                                                 <true>
          5        DO_ICALL                                         $6      
          6        ASSIGN                                                   !2, $6
   42     7        INIT_FCALL                                               'print_r'
          8        SEND_VAR                                                 !2
          9        DO_ICALL                                                 
   43    10        NEW                                              $9      'Router'
         11        SEND_VAR_EX                                              !2
         12        DO_FCALL                                      0          
         13        ASSIGN                                                   !3, $9
   44    14        INIT_METHOD_CALL                                         !3, 'getControllerFromPath'
         15        SEND_VAR_EX                                              !0
         16        DO_FCALL                                      0  $12     
         17        CONCAT                                           ~13     'Using+controller%3A+', $12
         18        ECHO                                                     ~13
         19      > RETURN                                                   1

Class Router:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WRrsL
function name:  __construct
number of ops:  4
compiled vars:  !0 = $routes
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   RECV                                             !0      
   29     1        ASSIGN_OBJ                                               'routes'
          2        OP_DATA                                                  !0
   30     3      > RETURN                                                   null

End of function __construct

Function getcontrollerfrompath:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 9
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 16
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WRrsL
function name:  getControllerFromPath
number of ops:  17
compiled vars:  !0 = $path
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   RECV                                             !0      
   33     1        FETCH_OBJ_R                                      ~1      'routes'
          2        ARRAY_KEY_EXISTS                                 ~2      !0, ~1
          3        TYPE_CHECK                                    8          ~2
          4      > JMPZ                                                     ~3, ->9
   34     5    >   FETCH_OBJ_R                                      ~4      'routes'
          6        FETCH_DIM_R                                      ~5      ~4, !0
          7      > RETURN                                                   ~5
          8*       JMP                                                      ->16
   35     9    >   FETCH_OBJ_R                                      ~6      'routes'
         10        ARRAY_KEY_EXISTS                                 ~7      '404', ~6
         11        TYPE_CHECK                                    8          ~7
         12      > JMPZ                                                     ~8, ->16
   36    13    >   FETCH_OBJ_R                                      ~9      'routes'
         14        FETCH_DIM_R                                      ~10     ~9, 404
         15      > RETURN                                                   ~10
   38    16    > > RETURN                                                   null

End of function getcontrollerfrompath

End of class Router.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
157.89 ms | 1400 KiB | 17 Q