Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Reflection to extend a class in runtime with php

Tags:

php

How can I use Reflection to extend a class in runtime?
I need A class is extended from B class.

class A{
    function methodA()
    {
        echo 'This is method A';
    }
}

class B{
    function methodB()
    {
        echo 'This is method B';
    }
}
like image 304
vietean Avatar asked Feb 02 '26 15:02

vietean


2 Answers

You can't do it using reflection, but you could using runkit. I really, really wouldn't recommend doing it though; if a class should extend another class, make it so from the beginning.

like image 67
deceze Avatar answered Feb 05 '26 05:02

deceze


You cannot. As the name suggests, Reflection is for reflection alone, gathering data about the code, and not modification.

like image 20
Dani Avatar answered Feb 05 '26 04:02

Dani