说我有MyClass.php
class MyClass
{
public static function myMethod()
{
// Here I want to know the line (and file) where my method has been called
}
}
和SomeOtherFile.php
// other code ...
MyClass::myMethod();
// other code ...
那么,有没有办法从SomeOtherFile获取该行,其中myMethod()已直接在myMethod中调用?我的意思是,不将该行作为参数传递。
答案 0 :(得分:4)
debug_backtrace()
应该做的工作:
class MyClass
{
public static function myMethod()
{
var_dump(debug_backtrace());
}
}