Debugging another PHP code, I would like to selectively override one of my classes. The class is enabled through:
require_once('classname.php');
But it appears in different places of the application. I would rather "simulate" require_onceso that it never starts at all. That is, just determine class classnamehow I want it. Then, the next time the file was require_once' ed, it will be marked as already loaded and therefore not reloaded.
I can create my own classname.php file, but I would prefer to keep the testing that I am doing, contained in a single file, as I am doing this, perhaps for many classes, and it would be easier for me to control overriding.
In Perl, what I would like to do would be:
$INC{'classname.pm'} = 1;
Is there a way to access the PHP equivalent of Perl %INC?
Update : consistently wondering what PHP is not letting you do ...
My workaround was to use runkit runkit_method_redefine . I load the classes that I was trying to prevent, and then overriding all the methods that I tried to βlayoutβ, for example:
require_once('classname.php');
runkit_method_redefine('classname','method','$params','return "testdata";');
source
share