3v4l.org

run code in 500+ PHP versions simultaneously
<?php // Declarations and code in the global namespace namespace { class A { public function __construct($x) { echo(get_called_class().'::__construct('.$x.")\n"); } public static function someMethod($y) { echo(get_called_class().'::someMethod('.$y.")\n"); } } // No namespace, no problem $className = 'A'; $o = new $className(3); $className::someMethod('abc'); } // Use another namespace namespace N { class B extends \A {} } // Another namespace again namespace M { use N\B as B; // Use full class name $newName = 'N\B'; $o = new $newName('namespaced'); $newName::someMethod('works'); // Using a class alias works when used in code $o = new B('this works'); // This doesn't work, the class name must be full $newName = 'B'; $o = new $newName("this doesn't work"); }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/lg2qC
function name:  (null)
number of ops:  31
compiled vars:  !0 = $className, !1 = $o, !2 = $newName
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    9     0  E >   ASSIGN                                                       !0, 'A'
   10     1        FETCH_CLASS                                       0  $4      !0
          2        NEW                                                  $5      $4
          3        SEND_VAL_EX                                                  3
          4        DO_FCALL                                          0          
          5        ASSIGN                                                       !1, $5
   11     6        FETCH_CLASS                                       0  $8      !0
          7        INIT_STATIC_METHOD_CALL                                      $8, 'someMethod'
          8        SEND_VAL_EX                                                  'abc'
          9        DO_FCALL                                          0          
   23    10        ASSIGN                                                       !2, 'N%5CB'
   24    11        FETCH_CLASS                                       0  $11     !2
         12        NEW                                                  $12     $11
         13        SEND_VAL_EX                                                  'namespaced'
         14        DO_FCALL                                          0          
         15        ASSIGN                                                       !1, $12
   25    16        FETCH_CLASS                                       0  $15     !2
         17        INIT_STATIC_METHOD_CALL                                      $15, 'someMethod'
         18        SEND_VAL_EX                                                  'works'
         19        DO_FCALL                                          0          
   27    20        NEW                                                  $17     'N%5CB'
         21        SEND_VAL_EX                                                  'this+works'
         22        DO_FCALL                                          0          
         23        ASSIGN                                                       !1, $17
   29    24        ASSIGN                                                       !2, 'B'
   30    25        FETCH_CLASS                                       0  $21     !2
         26        NEW                                                  $22     $21
         27        SEND_VAL_EX                                                  'this+doesn%27t+work'
         28        DO_FCALL                                          0          
         29        ASSIGN                                                       !1, $22
   31    30      > RETURN                                                       1

Class A:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/lg2qC
function name:  __construct
number of ops:  7
compiled vars:  !0 = $x
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    5     0  E >   RECV                                                 !0      
          1        GET_CALLED_CLASS                                     ~1      
          2        CONCAT                                               ~2      ~1, '%3A%3A__construct%28'
          3        CONCAT                                               ~3      ~2, !0
          4        CONCAT                                               ~4      ~3, '%29%0A'
          5        ECHO                                                         ~4
          6      > RETURN                                                       null

End of function __construct

Function somemethod:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/lg2qC
function name:  someMethod
number of ops:  7
compiled vars:  !0 = $y
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    6     0  E >   RECV                                                 !0      
          1        GET_CALLED_CLASS                                     ~1      
          2        CONCAT                                               ~2      ~1, '%3A%3AsomeMethod%28'
          3        CONCAT                                               ~3      ~2, !0
          4        CONCAT                                               ~4      ~3, '%29%0A'
          5        ECHO                                                         ~4
          6      > RETURN                                                       null

End of function somemethod

End of class A.

Class N\B:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/lg2qC
function name:  __construct
number of ops:  7
compiled vars:  !0 = $x
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    5     0  E >   RECV                                                 !0      
          1        GET_CALLED_CLASS                                     ~1      
          2        CONCAT                                               ~2      ~1, '%3A%3A__construct%28'
          3        CONCAT                                               ~3      ~2, !0
          4        CONCAT                                               ~4      ~3, '%29%0A'
          5        ECHO                                                         ~4
          6      > RETURN                                                       null

End of function __construct

Function somemethod:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/lg2qC
function name:  someMethod
number of ops:  7
compiled vars:  !0 = $y
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    6     0  E >   RECV                                                 !0      
          1        GET_CALLED_CLASS                                     ~1      
          2        CONCAT                                               ~2      ~1, '%3A%3AsomeMethod%28'
          3        CONCAT                                               ~3      ~2, !0
          4        CONCAT                                               ~4      ~3, '%29%0A'
          5        ECHO                                                         ~4
          6      > RETURN                                                       null

End of function somemethod

End of class N\B.

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
160.14 ms | 2843 KiB | 13 Q