3v4l.org

run code in 300+ PHP versions simultaneously
<?php class App { public static $classes = array(); public function register($name, Callable $generator) { var_dump($this::classes); exit; //$this::classes[$name] = $generator; } public function make($name) { if (!isset($this::classes[$name])) { throw new Exception('Invalid class name'); } //return $this::classes[$name](); } } $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/nt5d9
function name:  (null)
number of ops:  19
compiled vars:  !0 = $app, !1 = $c
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   NEW                                              $2      'App'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $2
   36     3        INIT_METHOD_CALL                                         !0, 'register'
          4        SEND_VAL_EX                                              'foo'
          5        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2Fnt5d9%3A36%240'
   38     6        SEND_VAL_EX                                              ~5
          7        DO_FCALL                                      0          
   61     8        INIT_METHOD_CALL                                         !0, 'register'
          9        SEND_VAL_EX                                              'foo'
         10        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2Fnt5d9%3A61%241'
   63    11        SEND_VAL_EX                                              ~7
         12        DO_FCALL                                      0          
   66    13        NEW                                              $9      'SomeController'
         14        DO_FCALL                                      0          
         15        ASSIGN                                                   !1, $9
   67    16        INIT_METHOD_CALL                                         !1, 'view'
         17        DO_FCALL                                      0          
         18      > RETURN                                                   1

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

End of function %00%7Bclosure%7D%2Fin%2Fnt5d9%3A36%240

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

End of function %00%7Bclosure%7D%2Fin%2Fnt5d9%3A61%241

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

End of function register

Function make:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 11
Branch analysis from position: 7
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/nt5d9
function name:  make
number of ops:  12
compiled vars:  !0 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
   15     1        FETCH_THIS                                       ~1      
          2        FETCH_CLASS                                   0  $2      ~1
          3        FETCH_CLASS_CONSTANT                             ~3      $2, 'classes'
          4        ISSET_ISEMPTY_DIM_OBJ                         0  ~4      ~3, !0
          5        BOOL_NOT                                         ~5      ~4
          6      > JMPZ                                                     ~5, ->11
   16     7    >   NEW                                              $6      'Exception'
          8        SEND_VAL_EX                                              'Invalid+class+name'
          9        DO_FCALL                                      0          
         10      > THROW                                         0          $6
   20    11    > > 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/nt5d9
function name:  bar
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E > > RETURN                                                   'static'
   32     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/nt5d9
function name:  view
number of ops:  10
compiled vars:  !0 = $app
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   45     0  E >   NEW                                              $1      'App'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
   46     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
   47     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/nt5d9
function name:  bar
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   56     0  E > > RETURN                                                   'can%27t+make+internal+methods+use+this.'
   57     1*     > RETURN                                                   null

End of function bar

End of class MyFoo.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
156.04 ms | 1404 KiB | 15 Q