I have read this previous question. My problem is similar: to debug some problems, I need to log all calls to functions in a source file includes/foo.php
to database:
<?php
function f1($arg1, $arg2) {
return $arg1 . "x" . $arg2;
}
...
function f9($foo, $bar=array(), $baz=0) {
return array(...);
}
What is the simplest way to do this? I've thought of moving includes/foo.php
to includes/foo.php_orig
, renaming all functions in that source (e.g. f1 to f1__orig, and so on), then put in my own wrapper includes/foo.php
:
<?php
include "includes/logger.php";
include "includes/foo.php_orig";
function f1($arg1, $arg2) {
$res = f1__orig($arg1, $arg2);
log_fcall(array($arg1, $arg2), $res);
return $res;
}
...
function f9($foo, $bar=array(), $baz=0) {
$res = f9__orig($foo, $bar, $baz);
log_fcall(array($foo, $bar, $baz), $res);
return $res;
}
But this feels so tedious and manual. Does PHP offer another mechanism? Or at least, some other constructs to ease the pains.