考虑以下代码:
class App {
public static function log($msg) {
echo $msg;
//echo WHAT_CLASS_CALLED_LOG;
//echo WHAT_LINE_CALLED_LOG;
}
}
class Tester {
public function Make() {
App::log('test');
}
}
$obj = new Tester();
$obj->Make();
是否可以在log方法中获取调用函数的类名和函数名? (没有明确地将它们发送到日志功能)
PS:我认为trigger_error就像窗帘背后那样,所以我想知道我是否能做到这一点。答案 0 :(得分:3)
我相信你正在寻找debug_backtrace
。
Returns an associative array. The possible returned elements are as follows:
Name Type Description
function string The current function name. See also __FUNCTION__.
line integer The current line number. See also __LINE__.
file string The current file name. See also __FILE__.
class string The current class name. See also __CLASS__
object object The current object.
type string The current call type. If a method call, "->" is returned. If a static method call, "::" is returned. If a function call, nothing is returned.
args array If inside a function, this lists the functions arguments. If inside an included file, this lists the included file name(s).
答案 1 :(得分:2)
可能debug_backtrace
可以提供帮助。查看PHP手册以获取功能描述: