I don't think you can do it in any "correct" way. My first thought was to use __call
, but that of course is only called for undefined functions.
And there's not really any way to dynamically rename the methods, unless you're already using RunKit
. (not that I know of or could find anyway).
If it's purely for debug purposes, you could set your own class autoloader to pre-process the files, change the method names, and then use the __call
magic method on your parent class.
spl_autoload_register(function($class){
$hackPath = '/home/_classes/'.$class;
if (!file_exists($hackPath)){
$realPath = '/home/classes/'.$class;
$file = file_get_contents($realPath);
$processedContent = //use regex or something to prepend all function names with an _.
file_put_contents($hackPath,$processedContent);
}
require_once $hackPath;
});
Then in your parent class
class parent {
public function __call($funcName,$arguments){
$this->myLogFunc($funcName,$arguments);
//since you prepended with an underscore
return call_user_func_array('_'.$funcName,$arguments);
}
This is a terrible way to do what you're asking, but it could work. The pre-processing of files might be slow, but you'd only need to do it if the originals changed (you can use filemtime
to check if it's changed).