3v4l.org

run code in 300+ PHP versions simultaneously
<?php namespace Core\Routing { interface Router { public function serve($uri); } class SimpleRouter implements Router { public function serve($uri) { echo 'Serving request: ', $uri, ' using ', __CLASS__; } } class FancyRouter implements Router { public function serve($uri) { echo 'Serving request: ', $uri, ' using ', __CLASS__; } } } namespace Core\Database { interface Connection { public function query($sql); } class MySQLConnection implements Connection { public function query($sql) { echo 'Querying: ', $sql, ' using ', __CLASS__; } } class MariaDBConnection implements Connection { public function query($sql) { echo 'Querying: ', $sql, ' using ', __CLASS__; } } } namespace Core { abstract class Application { protected static $instances = array(); private $properties = array(); public static function getInstance() { return isset(self::$instances[$className = get_called_class()]) ? self::$instances[$className] : self::$instances[$className] = new static(); } protected function __construct() { } public function __set($propertyName, $value) { $this->properties[$propertyName] = $value; } public function __get($propertyName) { return is_callable($this->properties[$propertyName]) ? $this->properties[$propertyName] = $this->properties[$propertyName]($this) : $this->properties[$propertyName]; } } abstract class WebApplication extends Application { protected $routerClassName = '\\Core\\Routing\\SimpleRouter'; // TODO: why not use constants here ??? maybe code should be allowed to modify dependencies at runtime ??? protected $databaseConnectionClassName = '\\Core\\Database\\MySQLConnection'; protected function __construct() { $this->router = function ($application) { //$routerClassName = $application->routerClassName; //return new $routerClassName(); return new $application->routerClassName(); }; $this->databaseConnection = function ($application) { $databaseConnectionClassName = $application->databaseConnectionClassName; return new $databaseConnectionClassName(); }; } } } namespace CompanyName { final class DiscussionsWebApplication extends \Core\WebApplication { protected $routerClassName = '\\Core\\Routing\\FancyRouter'; protected $databaseConnectionClassName = '\\Core\\Database\\MariaDBConnection'; } } namespace { CompanyName\DiscussionsWebApplication::getInstance()->router->serve('http://foo.bar/path/to/resource'); }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/JkXke
function name:  (null)
number of ops:  11
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   DECLARE_CLASS                                            'core%5Crouting%5Csimplerouter'
   12     1        DECLARE_CLASS                                            'core%5Crouting%5Cfancyrouter'
   23     2        DECLARE_CLASS                                            'core%5Cdatabase%5Cmysqlconnection'
   28     3        DECLARE_CLASS                                            'core%5Cdatabase%5Cmariadbconnection'
   77     4        INIT_STATIC_METHOD_CALL                                  'CompanyName%5CDiscussionsWebApplication', 'getInstance'
          5        DO_FCALL                                      0  $0      
          6        FETCH_OBJ_R                                      ~1      $0, 'router'
          7        INIT_METHOD_CALL                                         ~1, 'serve'
          8        SEND_VAL_EX                                              'http%3A%2F%2Ffoo.bar%2Fpath%2Fto%2Fresource'
          9        DO_FCALL                                      0          
   78    10      > RETURN                                                   1

Function %00core%5C%7Bclosure%7D%2Fin%2FJkXke%3A56%244:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/JkXke
function name:  Core\{closure}
number of ops:  7
compiled vars:  !0 = $application
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   56     0  E >   RECV                                             !0      
   59     1        FETCH_OBJ_R                                      ~1      !0, 'routerClassName'
          2        FETCH_CLASS                                   0  $2      ~1
          3        NEW                                              $3      $2
          4        DO_FCALL                                      0          
          5      > RETURN                                                   $3
   60     6*     > RETURN                                                   null

End of function %00core%5C%7Bclosure%7D%2Fin%2FJkXke%3A56%244

Function %00core%5C%7Bclosure%7D%2Fin%2FJkXke%3A61%245:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/JkXke
function name:  Core\{closure}
number of ops:  8
compiled vars:  !0 = $application, !1 = $databaseConnectionClassName
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   61     0  E >   RECV                                             !0      
   62     1        FETCH_OBJ_R                                      ~2      !0, 'databaseConnectionClassName'
          2        ASSIGN                                                   !1, ~2
   63     3        FETCH_CLASS                                   0  $4      !1
          4        NEW                                              $5      $4
          5        DO_FCALL                                      0          
          6      > RETURN                                                   $5
   64     7*     > RETURN                                                   null

End of function %00core%5C%7Bclosure%7D%2Fin%2FJkXke%3A61%245

Class Core\Routing\Router:
Function serve:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/JkXke
function name:  serve
number of ops:  2
compiled vars:  !0 = $uri
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
          1      > RETURN                                                   null

End of function serve

End of class Core\Routing\Router.

Class Core\Routing\SimpleRouter:
Function serve:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/JkXke
function name:  serve
number of ops:  6
compiled vars:  !0 = $uri
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   RECV                                             !0      
    9     1        ECHO                                                     'Serving+request%3A+'
          2        ECHO                                                     !0
          3        ECHO                                                     '+using+'
          4        ECHO                                                     'Core%5CRouting%5CSimpleRouter'
   10     5      > RETURN                                                   null

End of function serve

End of class Core\Routing\SimpleRouter.

Class Core\Routing\FancyRouter:
Function serve:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/JkXke
function name:  serve
number of ops:  6
compiled vars:  !0 = $uri
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   RECV                                             !0      
   14     1        ECHO                                                     'Serving+request%3A+'
          2        ECHO                                                     !0
          3        ECHO                                                     '+using+'
          4        ECHO                                                     'Core%5CRouting%5CFancyRouter'
   15     5      > RETURN                                                   null

End of function serve

End of class Core\Routing\FancyRouter.

Class Core\Database\Connection:
Function query:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/JkXke
function name:  query
number of ops:  2
compiled vars:  !0 = $sql
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   RECV                                             !0      
          1      > RETURN                                                   null

End of function query

End of class Core\Database\Connection.

Class Core\Database\MySQLConnection:
Function query:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/JkXke
function name:  query
number of ops:  6
compiled vars:  !0 = $sql
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
   25     1        ECHO                                                     'Querying%3A+'
          2        ECHO                                                     !0
          3        ECHO                                                     '+using+'
          4        ECHO                                                     'Core%5CDatabase%5CMySQLConnection'
   26     5      > RETURN                                                   null

End of function query

End of class Core\Database\MySQLConnection.

Class Core\Database\MariaDBConnection:
Function query:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/JkXke
function name:  query
number of ops:  6
compiled vars:  !0 = $sql
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   RECV                                             !0      
   30     1        ECHO                                                     'Querying%3A+'
          2        ECHO                                                     !0
          3        ECHO                                                     '+using+'
          4        ECHO                                                     'Core%5CDatabase%5CMariaDBConnection'
   31     5      > RETURN                                                   null

End of function query

End of class Core\Database\MariaDBConnection.

Class Core\Application:
Function getinstance:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 10
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/JkXke
function name:  getInstance
number of ops:  18
compiled vars:  !0 = $className
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   40     0  E >   INIT_NS_FCALL_BY_NAME                                    'Core%5Cget_called_class'
          1        DO_FCALL                                      0  $2      
          2        ASSIGN                                           ~3      !0, $2
          3        FETCH_STATIC_PROP_IS                             ~1      'instances'
          4        ISSET_ISEMPTY_DIM_OBJ                         0          ~1, ~3
          5      > JMPZ                                                     ~4, ->10
          6    >   FETCH_STATIC_PROP_R          unknown             ~5      'instances'
          7        FETCH_DIM_R                                      ~6      ~5, !0
          8        QM_ASSIGN                                        ~7      ~6
          9      > JMP                                                      ->16
         10    >   NEW                          static              $10     
         11        DO_FCALL                                      0          
         12        FETCH_STATIC_PROP_W          unknown             $8      'instances'
         13        ASSIGN_DIM                                       ~9      $8, !0
         14        OP_DATA                                                  $10
         15        QM_ASSIGN                                        ~7      ~9
         16    > > RETURN                                                   ~7
   41    17*     > RETURN                                                   null

End of function getinstance

Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/JkXke
function name:  __construct
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   43     0  E > > RETURN                                                   null

End of function __construct

Function __set:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/JkXke
function name:  __set
number of ops:  6
compiled vars:  !0 = $propertyName, !1 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   44     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   45     2        FETCH_OBJ_W                                      $2      'properties'
          3        ASSIGN_DIM                                               $2, !0
          4        OP_DATA                                                  !1
   46     5      > RETURN                                                   null

End of function __set

Function __get:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 19
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/JkXke
function name:  __get
number of ops:  24
compiled vars:  !0 = $propertyName
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   47     0  E >   RECV                                             !0      
   48     1        INIT_NS_FCALL_BY_NAME                                    'Core%5Cis_callable'
          2        CHECK_FUNC_ARG                                           
          3        FETCH_OBJ_FUNC_ARG                               $1      'properties'
          4        FETCH_DIM_FUNC_ARG                               $2      $1, !0
          5        SEND_FUNC_ARG                                            $2
          6        DO_FCALL                                      0  $3      
          7      > JMPZ                                                     $3, ->19
          8    >   FETCH_OBJ_R                                      ~6      'properties'
          9        FETCH_DIM_R                                      ~7      ~6, !0
         10        INIT_DYNAMIC_CALL                                        ~7
         11        FETCH_THIS                                       $8      
         12        SEND_VAR_EX                                              $8
         13        DO_FCALL                                      0  $9      
         14        FETCH_OBJ_W                                      $4      'properties'
         15        ASSIGN_DIM                                       ~5      $4, !0
         16        OP_DATA                                                  $9
         17        QM_ASSIGN                                        ~10     ~5
         18      > JMP                                                      ->22
         19    >   FETCH_OBJ_R                                      ~11     'properties'
         20        FETCH_DIM_R                                      ~12     ~11, !0
         21        QM_ASSIGN                                        ~10     ~12
         22    > > RETURN                                                   ~10
   49    23*     > RETURN                                                   null

End of function __get

End of class Core\Application.

Class Core\WebApplication:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/JkXke
function name:  __construct
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   56     0  E >   DECLARE_LAMBDA_FUNCTION                                  '%00core%5C%7Bclosure%7D%2Fin%2FJkXke%3A56%244'
          1        ASSIGN_OBJ                                               'router'
   60     2        OP_DATA                                                  ~1
   61     3        DECLARE_LAMBDA_FUNCTION                                  '%00core%5C%7Bclosure%7D%2Fin%2FJkXke%3A61%245'
          4        ASSIGN_OBJ                                               'databaseConnection'
   64     5        OP_DATA                                                  ~3
   65     6      > RETURN                                                   null

End of function __construct

Function getinstance:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 10
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/JkXke
function name:  getInstance
number of ops:  18
compiled vars:  !0 = $className
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   40     0  E >   INIT_NS_FCALL_BY_NAME                                    'Core%5Cget_called_class'
          1        DO_FCALL                                      0  $2      
          2        ASSIGN                                           ~3      !0, $2
          3        FETCH_STATIC_PROP_IS                             ~1      'instances'
          4        ISSET_ISEMPTY_DIM_OBJ                         0          ~1, ~3
          5      > JMPZ                                                     ~4, ->10
          6    >   FETCH_STATIC_PROP_R          unknown             ~5      'instances'
          7        FETCH_DIM_R                                      ~6      ~5, !0
          8        QM_ASSIGN                                        ~7      ~6
          9      > JMP                                                      ->16
         10    >   NEW                          static              $10     
         11        DO_FCALL                                      0          
         12        FETCH_STATIC_PROP_W          unknown             $8      'instances'
         13        ASSIGN_DIM                                       ~9      $8, !0
         14        OP_DATA                                                  $10
         15        QM_ASSIGN                                        ~7      ~9
         16    > > RETURN                                                   ~7
   41    17*     > RETURN                                                   null

End of function getinstance

Function __set:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/JkXke
function name:  __set
number of ops:  6
compiled vars:  !0 = $propertyName, !1 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   44     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   45     2        FETCH_OBJ_W                                      $2      'properties'
          3        ASSIGN_DIM                                               $2, !0
          4        OP_DATA                                                  !1
   46     5      > RETURN                                                   null

End of function __set

Function __get:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 19
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/JkXke
function name:  __get
number of ops:  24
compiled vars:  !0 = $propertyName
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   47     0  E >   RECV                                             !0      
   48     1        INIT_NS_FCALL_BY_NAME                                    'Core%5Cis_callable'
          2        CHECK_FUNC_ARG                                           
          3        FETCH_OBJ_FUNC_ARG                               $1      'properties'
          4        FETCH_DIM_FUNC_ARG                               $2      $1, !0
          5        SEND_FUNC_ARG                                            $2
          6        DO_FCALL                                      0  $3      
          7      > JMPZ                                                     $3, ->19
          8    >   FETCH_OBJ_R                                      ~6      'properties'
          9        FETCH_DIM_R                                      ~7      ~6, !0
         10        INIT_DYNAMIC_CALL                                        ~7
         11        FETCH_THIS                                       $8      
         12        SEND_VAR_EX                                              $8
         13        DO_FCALL                                      0  $9      
         14        FETCH_OBJ_W                                      $4      'properties'
         15        ASSIGN_DIM                                       ~5      $4, !0
         16        OP_DATA                                                  $9
         17        QM_ASSIGN                                        ~10     ~5
         18      > JMP                                                      ->22
         19    >   FETCH_OBJ_R                                      ~11     'properties'
         20        FETCH_DIM_R                                      ~12     ~11, !0
         21        QM_ASSIGN                                        ~10     ~12
         22    > > RETURN                                                   ~10
   49    23*     > RETURN                                                   null

End of function __get

End of class Core\WebApplication.

Class CompanyName\DiscussionsWebApplication:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/JkXke
function name:  __construct
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   56     0  E >   DECLARE_LAMBDA_FUNCTION                                  '%00core%5C%7Bclosure%7D%2Fin%2FJkXke%3A56%244'
          1        ASSIGN_OBJ                                               'router'
   60     2        OP_DATA                                                  ~1
   61     3        DECLARE_LAMBDA_FUNCTION                                  '%00core%5C%7Bclosure%7D%2Fin%2FJkXke%3A61%245'
          4        ASSIGN_OBJ                                               'databaseConnection'
   64     5        OP_DATA                                                  ~3
   65     6      > RETURN                                                   null

End of function __construct

Function getinstance:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 10
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/JkXke
function name:  getInstance
number of ops:  18
compiled vars:  !0 = $className
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   40     0  E >   INIT_NS_FCALL_BY_NAME                                    'Core%5Cget_called_class'
          1        DO_FCALL                                      0  $2      
          2        ASSIGN                                           ~3      !0, $2
          3        FETCH_STATIC_PROP_IS                             ~1      'instances'
          4        ISSET_ISEMPTY_DIM_OBJ                         0          ~1, ~3
          5      > JMPZ                                                     ~4, ->10
          6    >   FETCH_STATIC_PROP_R          unknown             ~5      'instances'
          7        FETCH_DIM_R                                      ~6      ~5, !0
          8        QM_ASSIGN                                        ~7      ~6
          9      > JMP                                                      ->16
         10    >   NEW                          static              $10     
         11        DO_FCALL                                      0          
         12        FETCH_STATIC_PROP_W          unknown             $8      'instances'
         13        ASSIGN_DIM                                       ~9      $8, !0
         14        OP_DATA                                                  $10
         15        QM_ASSIGN                                        ~7      ~9
         16    > > RETURN                                                   ~7
   41    17*     > RETURN                                                   null

End of function getinstance

Function __set:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/JkXke
function name:  __set
number of ops:  6
compiled vars:  !0 = $propertyName, !1 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   44     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   45     2        FETCH_OBJ_W                                      $2      'properties'
          3        ASSIGN_DIM                                               $2, !0
          4        OP_DATA                                                  !1
   46     5      > RETURN                                                   null

End of function __set

Function __get:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 19
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/JkXke
function name:  __get
number of ops:  24
compiled vars:  !0 = $propertyName
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   47     0  E >   RECV                                             !0      
   48     1        INIT_NS_FCALL_BY_NAME                                    'Core%5Cis_callable'
          2        CHECK_FUNC_ARG                                           
          3        FETCH_OBJ_FUNC_ARG                               $1      'properties'
          4        FETCH_DIM_FUNC_ARG                               $2      $1, !0
          5        SEND_FUNC_ARG                                            $2
          6        DO_FCALL                                      0  $3      
          7      > JMPZ                                                     $3, ->19
          8    >   FETCH_OBJ_R                                      ~6      'properties'
          9        FETCH_DIM_R                                      ~7      ~6, !0
         10        INIT_DYNAMIC_CALL                                        ~7
         11        FETCH_THIS                                       $8      
         12        SEND_VAR_EX                                              $8
         13        DO_FCALL                                      0  $9      
         14        FETCH_OBJ_W                                      $4      'properties'
         15        ASSIGN_DIM                                       ~5      $4, !0
         16        OP_DATA                                                  $9
         17        QM_ASSIGN                                        ~10     ~5
         18      > JMP                                                      ->22
         19    >   FETCH_OBJ_R                                      ~11     'properties'
         20        FETCH_DIM_R                                      ~12     ~11, !0
         21        QM_ASSIGN                                        ~10     ~12
         22    > > RETURN                                                   ~10
   49    23*     > RETURN                                                   null

End of function __get

End of class CompanyName\DiscussionsWebApplication.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
173.27 ms | 1424 KiB | 17 Q