3v4l.org

run code in 300+ PHP versions simultaneously
<?php class MVCFramework { var $url = ''; function __construct($url) { $this->url = $url; //HTTP_REQUEST URL $this->run(); } function run() { if ($route = Routes::getRoute($this->url)) { list($controller, $action) = $route; print_r($controller); //$controllerObj = new $$controller; //$controllerObj->$$action(); //template } else { print_r('404'); } } } class Routes { static $routes = array(); static function add($route, $controller, $action) { self::$routes[$route] = array($controller.'Controller', $action); } static function getRoutes() { return self::$routes; } static function getRoute($url) { return self::$routes[$url]; } } abstract class Model { // connect to DB and etc. } // controllers/BookController.php class BooksController { function index() { $books = Book::all(); } function show() { $id = 1; $books = Book::find(1); } } // models/Book.php class Book { static function all() { $books = array('Book', 'Book', 'Book'); return $books; } static function find() { $book = 'Book'; return $book; } } Routes::add('/books', 'Books', 'index'); Routes::add('/books/:id', 'Books', 'show'); $url = '/books'; new MVCFramework($url);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/8dEHU
function name:  (null)
number of ops:  16
compiled vars:  !0 = $url
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   92     0  E >   INIT_STATIC_METHOD_CALL                                  'Routes', 'add'
          1        SEND_VAL                                                 '%2Fbooks'
          2        SEND_VAL                                                 'Books'
          3        SEND_VAL                                                 'index'
          4        DO_FCALL                                      0          
   93     5        INIT_STATIC_METHOD_CALL                                  'Routes', 'add'
          6        SEND_VAL                                                 '%2Fbooks%2F%3Aid'
          7        SEND_VAL                                                 'Books'
          8        SEND_VAL                                                 'show'
          9        DO_FCALL                                      0          
   96    10        ASSIGN                                                   !0, '%2Fbooks'
   98    11        NEW                                              $4      'MVCFramework'
         12        SEND_VAR_EX                                              !0
         13        DO_FCALL                                      0          
         14        FREE                                                     $4
         15      > RETURN                                                   1

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

End of function __construct

Function run:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 17
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/8dEHU
function name:  run
number of ops:  21
compiled vars:  !0 = $route, !1 = $controller, !2 = $action
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   INIT_STATIC_METHOD_CALL                                  'Routes', 'getRoute'
          1        CHECK_FUNC_ARG                                           
          2        FETCH_OBJ_FUNC_ARG                               $3      'url'
          3        SEND_FUNC_ARG                                            $3
          4        DO_FCALL                                      0  $4      
          5        ASSIGN                                           ~5      !0, $4
          6      > JMPZ                                                     ~5, ->17
   16     7    >   QM_ASSIGN                                        ~6      !0
          8        FETCH_LIST_R                                     $7      ~6, 0
          9        ASSIGN                                                   !1, $7
         10        FETCH_LIST_R                                     $9      ~6, 1
         11        ASSIGN                                                   !2, $9
         12        FREE                                                     ~6
   18    13        INIT_FCALL                                               'print_r'
         14        SEND_VAR                                                 !1
         15        DO_ICALL                                                 
         16      > JMP                                                      ->20
   26    17    >   INIT_FCALL                                               'print_r'
         18        SEND_VAL                                                 '404'
         19        DO_ICALL                                                 
   28    20    > > RETURN                                                   null

End of function run

End of class MVCFramework.

Class Routes:
Function add:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/8dEHU
function name:  add
number of ops:  10
compiled vars:  !0 = $route, !1 = $controller, !2 = $action
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   37     3        CONCAT                                           ~5      !1, 'Controller'
          4        INIT_ARRAY                                       ~6      ~5
          5        ADD_ARRAY_ELEMENT                                ~6      !2
          6        FETCH_STATIC_PROP_W          global              $3      'routes'
          7        ASSIGN_DIM                                               $3, !0
          8        OP_DATA                                                  ~6
   38     9      > RETURN                                                   null

End of function add

Function getroutes:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/8dEHU
function name:  getRoutes
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   42     0  E >   FETCH_STATIC_PROP_R          unknown             ~0      'routes'
          1      > RETURN                                                   ~0
   43     2*     > RETURN                                                   null

End of function getroutes

Function getroute:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/8dEHU
function name:  getRoute
number of ops:  5
compiled vars:  !0 = $url
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   45     0  E >   RECV                                             !0      
   47     1        FETCH_STATIC_PROP_R          unknown             ~1      'routes'
          2        FETCH_DIM_R                                      ~2      ~1, !0
          3      > RETURN                                                   ~2
   48     4*     > RETURN                                                   null

End of function getroute

End of class Routes.

Class Model: [no user functions]
Class BooksController:
Function index:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/8dEHU
function name:  index
number of ops:  4
compiled vars:  !0 = $books
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   62     0  E >   INIT_STATIC_METHOD_CALL                                  'Book', 'all'
          1        DO_FCALL                                      0  $1      
          2        ASSIGN                                                   !0, $1
   63     3      > RETURN                                                   null

End of function index

Function show:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/8dEHU
function name:  show
number of ops:  6
compiled vars:  !0 = $id, !1 = $books
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   67     0  E >   ASSIGN                                                   !0, 1
   68     1        INIT_STATIC_METHOD_CALL                                  'Book', 'find'
          2        SEND_VAL_EX                                              1
          3        DO_FCALL                                      0  $3      
          4        ASSIGN                                                   !1, $3
   69     5      > RETURN                                                   null

End of function show

End of class BooksController.

Class Book:
Function all:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/8dEHU
function name:  all
number of ops:  3
compiled vars:  !0 = $books
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   79     0  E >   ASSIGN                                                   !0, <array>
   80     1      > RETURN                                                   !0
   81     2*     > RETURN                                                   null

End of function all

Function find:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/8dEHU
function name:  find
number of ops:  3
compiled vars:  !0 = $book
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   85     0  E >   ASSIGN                                                   !0, 'Book'
   86     1      > RETURN                                                   !0
   87     2*     > RETURN                                                   null

End of function find

End of class Book.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
152.82 ms | 1404 KiB | 15 Q