3v4l.org

run code in 300+ PHP versions simultaneously
<?php // controllers/BookController.php class BooksController { function index() { $books = Book::all(); } function show() { $id = 1; $books = Book::find(1); } } 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. } // 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/OW1AN
function name:  (null)
number of ops:  16
compiled vars:  !0 = $url
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   93     0  E >   INIT_STATIC_METHOD_CALL                                  'Routes', 'add'
          1        SEND_VAL                                                 '%2Fbooks'
          2        SEND_VAL                                                 'Books'
          3        SEND_VAL                                                 'index'
          4        DO_FCALL                                      0          
   94     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          
   97    10        ASSIGN                                                   !0, '%2Fbooks'
   99    11        NEW                                              $4      'MVCFramework'
         12        SEND_VAR_EX                                              !0
         13        DO_FCALL                                      0          
         14        FREE                                                     $4
         15      > RETURN                                                   1

Class BooksController:
Function index:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OW1AN
function name:  index
number of ops:  4
compiled vars:  !0 = $books
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   INIT_STATIC_METHOD_CALL                                  'Book', 'all'
          1        DO_FCALL                                      0  $1      
          2        ASSIGN                                                   !0, $1
   10     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/OW1AN
function name:  show
number of ops:  6
compiled vars:  !0 = $id, !1 = $books
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   ASSIGN                                                   !0, 1
   15     1        INIT_STATIC_METHOD_CALL                                  'Book', 'find'
          2        SEND_VAL_EX                                              1
          3        DO_FCALL                                      0  $3      
          4        ASSIGN                                                   !1, $3
   16     5      > RETURN                                                   null

End of function show

End of class BooksController.

Class MVCFramework:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OW1AN
function name:  __construct
number of ops:  6
compiled vars:  !0 = $url
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
   26     1        ASSIGN_OBJ                                               'url'
          2        OP_DATA                                                  !0
   27     3        INIT_METHOD_CALL                                         'run'
          4        DO_FCALL                                      0          
   28     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 = 18
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OW1AN
function name:  run
number of ops:  22
compiled vars:  !0 = $route, !1 = $controller, !2 = $action
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     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, ->18
   33     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
   35    13        INIT_FCALL                                               'print_r'
         14        FETCH_R                      local               ~11     !1
         15        SEND_VAL                                                 ~11
         16        DO_ICALL                                                 
         17      > JMP                                                      ->21
   43    18    >   INIT_FCALL                                               'print_r'
         19        SEND_VAL                                                 '404'
         20        DO_ICALL                                                 
   45    21    > > 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/OW1AN
function name:  add
number of ops:  10
compiled vars:  !0 = $route, !1 = $controller, !2 = $action
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   52     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   54     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
   55     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/OW1AN
function name:  getRoutes
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   59     0  E >   FETCH_STATIC_PROP_R          unknown             ~0      'routes'
          1      > RETURN                                                   ~0
   60     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/OW1AN
function name:  getRoute
number of ops:  5
compiled vars:  !0 = $url
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   62     0  E >   RECV                                             !0      
   64     1        FETCH_STATIC_PROP_R          unknown             ~1      'routes'
          2        FETCH_DIM_R                                      ~2      ~1, !0
          3      > RETURN                                                   ~2
   65     4*     > RETURN                                                   null

End of function getroute

End of class Routes.

Class Model: [no user functions]
Class Book:
Function all:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OW1AN
function name:  all
number of ops:  3
compiled vars:  !0 = $books
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   80     0  E >   ASSIGN                                                   !0, <array>
   81     1      > RETURN                                                   !0
   82     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/OW1AN
function name:  find
number of ops:  3
compiled vars:  !0 = $book
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   86     0  E >   ASSIGN                                                   !0, 'Book'
   87     1      > RETURN                                                   !0
   88     2*     > RETURN                                                   null

End of function find

End of class Book.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
146.68 ms | 1396 KiB | 15 Q