3v4l.org

run code in 300+ PHP versions simultaneously
<?php class App { public static $classes = array(); public function register($name, Callable $generator) { $this::$classes[$name] = $generator; } public function make() { $args = func_get_args(); $name = array_shift($args); if (!isset($this::$classes[$name])) { throw new Exception('Invalid class name'); } $classes =& $this::$classes; return call_user_func_array($classes[$name], $args); } } $app = new App; // Internal declaration class Foo { public static function bar() { return 'static'; } } $app->register('foo', function() { return new Foo; }); // Internal Usage class SomeController { public function view() { $app = new App; echo $app->make('foo')->bar(); } } // Some extending application class MyFoo extends Foo { public static function bar() { return 'can\'t make internal methods use this.'; } } $app->register('foo', function() { return new MyFoo; }); $c = new SomeController; $c->view();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QJSFB
function name:  (null)
number of ops:  19
compiled vars:  !0 = $app, !1 = $c
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   NEW                                              $2      'App'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $2
   37     3        INIT_METHOD_CALL                                         !0, 'register'
          4        SEND_VAL_EX                                              'foo'
          5        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FQJSFB%3A37%240'
   39     6        SEND_VAL_EX                                              ~5
          7        DO_FCALL                                      0          
   62     8        INIT_METHOD_CALL                                         !0, 'register'
          9        SEND_VAL_EX                                              'foo'
         10        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FQJSFB%3A62%241'
   64    11        SEND_VAL_EX                                              ~7
         12        DO_FCALL                                      0          
   67    13        NEW                                              $9      'SomeController'
         14        DO_FCALL                                      0          
         15        ASSIGN                                                   !1, $9
   68    16        INIT_METHOD_CALL                                         !1, 'view'
         17        DO_FCALL                                      0          
         18      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FQJSFB%3A37%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QJSFB
function name:  {closure}
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   38     0  E >   NEW                                              $0      'Foo'
          1        DO_FCALL                                      0          
          2      > RETURN                                                   $0
   39     3*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FQJSFB%3A37%240

Function %00%7Bclosure%7D%2Fin%2FQJSFB%3A62%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QJSFB
function name:  {closure}
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   63     0  E >   NEW                                              $0      'MyFoo'
          1        DO_FCALL                                      0          
          2      > RETURN                                                   $0
   64     3*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FQJSFB%3A62%241

Class App:
Function register:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QJSFB
function name:  register
number of ops:  8
compiled vars:  !0 = $name, !1 = $generator
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    8     2        FETCH_THIS                                       ~2      
          3        FETCH_CLASS                                   0  $3      ~2
          4        FETCH_STATIC_PROP_W          global              $4      'classes'
          5        ASSIGN_DIM                                               $4, !0
          6        OP_DATA                                                  !1
    9     7      > RETURN                                                   null

End of function register

Function make:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 16
Branch analysis from position: 12
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QJSFB
function name:  make
number of ops:  27
compiled vars:  !0 = $args, !1 = $name, !2 = $classes
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   FUNC_GET_ARGS                                    ~3      
          1        ASSIGN                                                   !0, ~3
   13     2        INIT_FCALL                                               'array_shift'
          3        SEND_REF                                                 !0
          4        DO_ICALL                                         $5      
          5        ASSIGN                                                   !1, $5
   15     6        FETCH_THIS                                       ~7      
          7        FETCH_CLASS                                   0  $8      ~7
          8        FETCH_STATIC_PROP_IS                             ~9      'classes', $8
          9        ISSET_ISEMPTY_DIM_OBJ                         0  ~10     ~9, !1
         10        BOOL_NOT                                         ~11     ~10
         11      > JMPZ                                                     ~11, ->16
   16    12    >   NEW                                              $12     'Exception'
         13        SEND_VAL_EX                                              'Invalid+class+name'
         14        DO_FCALL                                      0          
         15      > THROW                                         0          $12
   19    16    >   FETCH_THIS                                       ~14     
         17        FETCH_CLASS                                   0  $15     ~14
         18        FETCH_STATIC_PROP_W          unknown             $16     'classes'
         19        ASSIGN_REF                                               !2, $16
   20    20        FETCH_DIM_R                                      ~18     !2, !1
         21        INIT_USER_CALL                                0          'call_user_func_array', ~18
         22        SEND_ARRAY                                               !0
         23        CHECK_UNDEF_ARGS                                         
         24        DO_FCALL                                      0  $19     
         25      > RETURN                                                   $19
   21    26*     > RETURN                                                   null

End of function make

End of class App.

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

End of function bar

End of class Foo.

Class SomeController:
Function view:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QJSFB
function name:  view
number of ops:  10
compiled vars:  !0 = $app
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   46     0  E >   NEW                                              $1      'App'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
   47     3        INIT_METHOD_CALL                                         !0, 'make'
          4        SEND_VAL_EX                                              'foo'
          5        DO_FCALL                                      0  $4      
          6        INIT_METHOD_CALL                                         $4, 'bar'
          7        DO_FCALL                                      0  $5      
          8        ECHO                                                     $5
   48     9      > RETURN                                                   null

End of function view

End of class SomeController.

Class MyFoo:
Function bar:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QJSFB
function name:  bar
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   57     0  E > > RETURN                                                   'can%27t+make+internal+methods+use+this.'
   58     1*     > RETURN                                                   null

End of function bar

End of class MyFoo.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
152.44 ms | 1396 KiB | 15 Q