2011-03-23 47 views
0

考慮以下代碼:輸出調用函數信息

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(); 

是可能得到的類名,並在日誌方法調用函數的函數名? (沒有明確地將它們發送到日誌功能)

PS:我認爲trigger_error的作用就像在窗簾後面,所以我想知道如果我能做到這一點。

回答

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).