3v4l.org

run code in 300+ PHP versions simultaneously
<?php class App { public static $classes = array(); public static function register($name, Callable $generator) { static::$classes[$name] = $generator; } public static function make($name) { if (!isset(static::$classes[$name])) { throw new Exception('Invalid class name'); } return static::$classes[$name](); } } // Internal declaration class Foo { public static function bar() { return 'static'; } } App::register('foo', function() { return new Foo; }); // Internal Usage class SomeController { public function view() { 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/S3GCN
function name:  (null)
number of ops:  16
compiled vars:  !0 = $c
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   INIT_STATIC_METHOD_CALL                                  'App', 'register'
          1        SEND_VAL                                                 'foo'
          2        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FS3GCN%3A34%240'
   36     3        SEND_VAL                                                 ~1
          4        DO_FCALL                                      0          
   59     5        INIT_STATIC_METHOD_CALL                                  'App', 'register'
          6        SEND_VAL                                                 'foo'
          7        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FS3GCN%3A59%241'
   61     8        SEND_VAL                                                 ~3
          9        DO_FCALL                                      0          
   64    10        NEW                                              $5      'SomeController'
         11        DO_FCALL                                      0          
         12        ASSIGN                                                   !0, $5
   65    13        INIT_METHOD_CALL                                         !0, 'view'
         14        DO_FCALL                                      0          
         15      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FS3GCN%3A34%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/S3GCN
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%2FS3GCN%3A34%240

Function %00%7Bclosure%7D%2Fin%2FS3GCN%3A59%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/S3GCN
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%2FS3GCN%3A59%241

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

End of function register

Function make:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 9
Branch analysis from position: 5
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/S3GCN
function name:  make
number of ops:  15
compiled vars:  !0 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   RECV                                             !0      
   14     1        FETCH_STATIC_PROP_IS                             ~1      'classes'
          2        ISSET_ISEMPTY_DIM_OBJ                         0  ~2      ~1, !0
          3        BOOL_NOT                                         ~3      ~2
          4      > JMPZ                                                     ~3, ->9
   15     5    >   NEW                                              $4      'Exception'
          6        SEND_VAL_EX                                              'Invalid+class+name'
          7        DO_FCALL                                      0          
          8      > THROW                                         0          $4
   18     9    >   FETCH_STATIC_PROP_R          unknown             ~6      'classes'
         10        FETCH_DIM_R                                      ~7      ~6, !0
         11        INIT_DYNAMIC_CALL                                        ~7
         12        DO_FCALL                                      0  $8      
         13      > RETURN                                                   $8
   19    14*     > 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/S3GCN
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/S3GCN
function name:  view
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   43     0  E >   INIT_STATIC_METHOD_CALL                                  'App', 'make'
          1        SEND_VAL                                                 'foo'
          2        DO_FCALL                                      0  $0      
          3        INIT_METHOD_CALL                                         $0, 'bar'
          4        DO_FCALL                                      0  $1      
          5        ECHO                                                     $1
   44     6      > 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/S3GCN
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:
140.17 ms | 943 KiB | 14 Q