假设我有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中直接调用?我的意思是,不传递行作为参数
debug_backtrace()
应该做这项工作:
class MyClass
{
public static function myMethod()
{
var_dump(debug_backtrace());
}
}