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($name) { if (!isset($this::$classes[$name])) { throw new Exception('Invalid class name'); } var_dump($this::$classes);exit; 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/RC7jh
function name:  (null)
number of ops:  19
compiled vars:  !0 = $app, !1 = $c
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   NEW                                              $2      'App'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $2
   34     3        INIT_METHOD_CALL                                         !0, 'register'
          4        SEND_VAL_EX                                              'foo'
          5        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FRC7jh%3A34%240'
   36     6        SEND_VAL_EX                                              ~5
          7        DO_FCALL                                      0          
   59     8        INIT_METHOD_CALL                                         !0, 'register'
          9        SEND_VAL_EX                                              'foo'
         10        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FRC7jh%3A59%241'
   61    11        SEND_VAL_EX                                              ~7
         12        DO_FCALL                                      0          
   64    13        NEW                                              $9      'SomeController'
         14        DO_FCALL                                      0          
         15        ASSIGN                                                   !1, $9
   65    16        INIT_METHOD_CALL                                         !1, 'view'
         17        DO_FCALL                                      0          
         18      > RETURN                                                   1

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

End of function %00%7Bclosure%7D%2Fin%2FRC7jh%3A34%240

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

End of function %00%7Bclosure%7D%2Fin%2FRC7jh%3A59%241

Class App:
Function register:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/RC7jh
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 = 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 = 79) Position 1 = -2
filename:       /in/RC7jh
function name:  make
number of ops:  26
compiled vars:  !0 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   RECV                                             !0      
   12     1        FETCH_THIS                                       ~1      
          2        FETCH_CLASS                                   0  $2      ~1
          3        FETCH_STATIC_PROP_IS                             ~3      'classes', $2
          4        ISSET_ISEMPTY_DIM_OBJ                         0  ~4      ~3, !0
          5        BOOL_NOT                                         ~5      ~4
          6      > JMPZ                                                     ~5, ->11
   13     7    >   NEW                                              $6      'Exception'
          8        SEND_VAL_EX                                              'Invalid+class+name'
          9        DO_FCALL                                      0          
         10      > THROW                                         0          $6
   16    11    >   INIT_FCALL                                               'var_dump'
         12        FETCH_THIS                                       ~8      
         13        FETCH_CLASS                                   0  $9      ~8
         14        FETCH_STATIC_PROP_R          unknown             ~10     'classes'
         15        SEND_VAL                                                 ~10
         16        DO_ICALL                                                 
         17      > EXIT                                                     
   17    18*       FETCH_THIS                                       ~12     
         19*       FETCH_CLASS                                   0  $13     ~12
         20*       FETCH_STATIC_PROP_R          unknown             ~14     'classes'
         21*       FETCH_DIM_R                                      ~15     ~14, !0
         22*       INIT_DYNAMIC_CALL                                        ~15
         23*       DO_FCALL                                      0  $16     
         24*       RETURN                                                   $16
   18    25*     > 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/RC7jh
function name:  bar
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E > > RETURN                                                   'static'
   30     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/RC7jh
function name:  view
number of ops:  10
compiled vars:  !0 = $app
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   43     0  E >   NEW                                              $1      'App'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
   44     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
   45     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/RC7jh
function name:  bar
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   54     0  E > > RETURN                                                   'can%27t+make+internal+methods+use+this.'
   55     1*     > RETURN                                                   null

End of function bar

End of class MyFoo.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
155.59 ms | 1404 KiB | 15 Q