3v4l.org

run code in 300+ PHP versions simultaneously
<?php // request to php with type $requestedUri = $_SERVER['REQUEST_URI'] = 'http://www.testing.com/login'; $requestedUriWithQuery = $requestedUri . '?name=adam&password=password'; // parse request $parsed = parse_url($requestedUriWithQuery); $parsedQuery = []; parse_str($parsed['query'], $parsedQuery); // check request print_r([ $parsed, $parsedQuery ]); // controllers $controllers = [ '/login' => new class { public function action($request) { return "LOGIN " . implode(", ", $request); } }, '/' => new class { public function action($request) { return "HOME " . implode(", ", $request); } }, ]; // check controllers if(array_key_exists($parsed["path"], $controllers )){ echo $controllers [ $request['path'] ]->action($parsedQuery); }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 33, Position 2 = 39
Branch analysis from position: 33
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 39
filename:       /in/cdAkY
function name:  (null)
number of ops:  40
compiled vars:  !0 = $requestedUri, !1 = $requestedUriWithQuery, !2 = $parsed, !3 = $parsedQuery, !4 = $controllers, !5 = $request
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   FETCH_W                      global              $6      '_SERVER'
          1        ASSIGN_DIM                                       ~7      $6, 'REQUEST_URI'
          2        OP_DATA                                                  'http%3A%2F%2Fwww.testing.com%2Flogin'
          3        ASSIGN                                                   !0, ~7
    5     4        CONCAT                                           ~9      !0, '%3Fname%3Dadam%26password%3Dpassword'
          5        ASSIGN                                                   !1, ~9
    9     6        INIT_FCALL                                               'parse_url'
          7        SEND_VAR                                                 !1
          8        DO_ICALL                                         $11     
          9        ASSIGN                                                   !2, $11
   10    10        ASSIGN                                                   !3, <array>
   12    11        INIT_FCALL                                               'parse_str'
         12        FETCH_DIM_R                                      ~14     !2, 'query'
         13        SEND_VAL                                                 ~14
         14        SEND_REF                                                 !3
         15        DO_ICALL                                                 
   15    16        INIT_FCALL                                               'print_r'
   16    17        INIT_ARRAY                                       ~16     !2
   17    18        ADD_ARRAY_ELEMENT                                ~16     !3
         19        SEND_VAL                                                 ~16
         20        DO_ICALL                                                 
   24    21        DECLARE_ANON_CLASS                               <unknown> 
         22        NEW                                              $19     $18
         23        DO_FCALL                                      0          
         24        INIT_ARRAY                                       ~21     $19, '%2Flogin'
   31    25        DECLARE_ANON_CLASS                               <unknown> 
         26        NEW                                              $23     $22
         27        DO_FCALL                                      0          
         28        ADD_ARRAY_ELEMENT                                ~21     $23, '%2F'
   22    29        ASSIGN                                                   !4, ~21
   41    30        FETCH_DIM_R                                      ~26     !2, 'path'
         31        ARRAY_KEY_EXISTS                                         ~26, !4
         32      > JMPZ                                                     ~27, ->39
   43    33    >   FETCH_DIM_R                                      ~28     !5, 'path'
         34        FETCH_DIM_R                                      ~29     !4, ~28
         35        INIT_METHOD_CALL                                         ~29, 'action'
         36        SEND_VAR_EX                                              !3
         37        DO_FCALL                                      0  $30     
         38        ECHO                                                     $30
   45    39    > > RETURN                                                   1

Class class@anonymous:
Function action:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/cdAkY
function name:  action
number of ops:  8
compiled vars:  !0 = $request
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   RECV                                             !0      
   27     1        INIT_FCALL                                               'implode'
          2        SEND_VAL                                                 '%2C+'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $1      
          5        CONCAT                                           ~2      'LOGIN+', $1
          6      > RETURN                                                   ~2
   28     7*     > RETURN                                                   null

End of function action

End of class class@anonymous.

Class class@anonymous:
Function action:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/cdAkY
function name:  action
number of ops:  8
compiled vars:  !0 = $request
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   RECV                                             !0      
   34     1        INIT_FCALL                                               'implode'
          2        SEND_VAL                                                 '%2C+'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $1      
          5        CONCAT                                           ~2      'HOME+', $1
          6      > RETURN                                                   ~2
   35     7*     > RETURN                                                   null

End of function action

End of class class@anonymous.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
168.48 ms | 1400 KiB | 21 Q