3v4l.org

run code in 300+ PHP versions simultaneously
<?php $anonymous = new class { public function echoMsg(): void { echo 'Hello World' . PHP_EOL; } }; // get_class($anonymous) で無名クラスのPHP内での名前を得る // class_alias で IHaveName というクラス名のエイリアスを作る class_alias(get_class($anonymous), 'IHaveName'); // 無名クラスのエイリアスである IHaveName を継承させる class ExtendAnonymous extends IHaveName { } // 動く $instance = new ExtendAnonymous(); $instance->echoMsg(); // Hello World var_dump($instance); // object(ExtendAnonymous)#1 (0) {} var_dump(get_class($instance)); // string(15) "ExtendAnonymous" var_dump($instance instanceof $anonymous); // bool(true)
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ZoV4D
function name:  (null)
number of ops:  28
compiled vars:  !0 = $anonymous, !1 = $instance
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   DECLARE_ANON_CLASS                               <true>  
          1        NEW                                              $3      $2
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $3
   11     4        INIT_FCALL                                               'class_alias'
          5        GET_CLASS                                        ~6      !0
          6        SEND_VAL                                                 ~6
          7        SEND_VAL                                                 'IHaveName'
          8        DO_ICALL                                                 
   14     9        DECLARE_CLASS                                            'extendanonymous', 'ihavename'
   18    10        NEW                                              $8      'ExtendAnonymous'
         11        DO_FCALL                                      0          
         12        ASSIGN                                                   !1, $8
   19    13        INIT_METHOD_CALL                                         !1, 'echoMsg'
         14        DO_FCALL                                      0          
   20    15        INIT_FCALL                                               'var_dump'
         16        SEND_VAR                                                 !1
         17        DO_ICALL                                                 
   21    18        INIT_FCALL                                               'var_dump'
         19        GET_CLASS                                        ~13     !1
         20        SEND_VAL                                                 ~13
         21        DO_ICALL                                                 
   22    22        INIT_FCALL                                               'var_dump'
         23        FETCH_CLASS                                   0  $15     !0
         24        INSTANCEOF                                       ~16     !1, $15
         25        SEND_VAL                                                 ~16
         26        DO_ICALL                                                 
         27      > RETURN                                                   1

Class class@anonymous:
Function echomsg:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ZoV4D
function name:  echoMsg
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   ECHO                                                     'Hello+World%0A'
    7     1      > RETURN                                                   null

End of function echomsg

End of class class@anonymous.

Class ExtendAnonymous: [no user functions]

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
150.47 ms | 1461 KiB | 15 Q