3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Animal { public function eat() { echo 'Yummy!'; } } class Plant { public $size = 0; public function grow() { echo 'I\'m level '.++$this->size; } } if (rand(0, 1) == 0) $base = 'Animal'; else $base = 'Plant'; class_alias($base, "LifeformBase"); class Lifeform extends LifeformBase { } var_dump(new Lifeform); // similar for ReflectionClass, you just need to fetch the name // inheritance by anonymous class; also requires an object representing the anonymous class, like Closure is for anonymous functions. function get_base_animal_class() { return new class extends Animal { public $color; public function hiss() { echo 'Hiss!'; } }; } class_alias(get_class(get_base_animal_class()), "AnonBase"); $tiger_class = new class extends AnonBase { public $color = 'orange'; }; var_dump($tiger_class->hiss(), $tiger_class->color);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 8
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/SKWdW
function name:  (null)
number of ops:  38
compiled vars:  !0 = $base, !1 = $tiger_class
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   INIT_FCALL                                               'rand'
          1        SEND_VAL                                                 0
          2        SEND_VAL                                                 1
          3        DO_ICALL                                         $2      
          4        IS_EQUAL                                                 $2, 0
          5      > JMPZ                                                     ~3, ->8
          6    >   ASSIGN                                                   !0, 'Animal'
          7      > JMP                                                      ->9
          8    >   ASSIGN                                                   !0, 'Plant'
   13     9    >   INIT_FCALL                                               'class_alias'
         10        SEND_VAR                                                 !0
         11        SEND_VAL                                                 'LifeformBase'
         12        DO_ICALL                                                 
   14    13        DECLARE_CLASS                                            'lifeform', 'lifeformbase'
   16    14        INIT_FCALL                                               'var_dump'
         15        NEW                                              $7      'Lifeform'
         16        DO_FCALL                                      0          
         17        SEND_VAR                                                 $7
         18        DO_ICALL                                                 
   28    19        INIT_FCALL                                               'class_alias'
         20        INIT_FCALL                                               'get_base_animal_class'
         21        DO_FCALL                                      0  $10     
         22        GET_CLASS                                        ~11     $10
         23        SEND_VAL                                                 ~11
         24        SEND_VAL                                                 'AnonBase'
         25        DO_ICALL                                                 
   29    26        DECLARE_ANON_CLASS                               <unknown> 'anonbase'
         27        NEW                                              $14     $13
         28        DO_FCALL                                      0          
         29        ASSIGN                                                   !1, $14
   32    30        INIT_FCALL                                               'var_dump'
         31        INIT_METHOD_CALL                                         !1, 'hiss'
         32        DO_FCALL                                      0  $17     
         33        SEND_VAR                                                 $17
         34        FETCH_OBJ_R                                      ~18     !1, 'color'
         35        SEND_VAL                                                 ~18
         36        DO_ICALL                                                 
         37      > RETURN                                                   1

Function get_base_animal_class:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/SKWdW
function name:  get_base_animal_class
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   DECLARE_ANON_CLASS                               <unknown> 'animal'
          1        NEW                                              $1      $0
          2        DO_FCALL                                      0          
          3      > RETURN                                                   $1
   27     4*     > RETURN                                                   null

End of function get_base_animal_class

Class Animal:
Function eat:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/SKWdW
function name:  eat
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   ECHO                                                     'Yummy%21'
          1      > RETURN                                                   null

End of function eat

End of class Animal.

Class Plant:
Function grow:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/SKWdW
function name:  grow
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   PRE_INC_OBJ                                      ~0      'size'
          1        CONCAT                                           ~1      'I%27m+level+', ~0
          2        ECHO                                                     ~1
          3      > RETURN                                                   null

End of function grow

End of class Plant.

Class Lifeform: [no user functions]
Class Animal@anonymous:
Function hiss:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/SKWdW
function name:  hiss
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   ECHO                                                     'Hiss%21'
          1      > RETURN                                                   null

End of function hiss

End of class Animal@anonymous.

Class AnonBase@anonymous: [no user functions]

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
141.64 ms | 1007 KiB | 17 Q