The PHP debug_backtrace () function generates a BackTrace
the function returns an associative array .
下面是可能返回的元素
function |
string |
the current function name |
Line |
Integer |
The current line number |
File |
String |
The current file name |
Object |
Object |
Current Object |
Type |
String |
Current invocation type, possible invocation: return: "-"-Method call Returns: "::"-static method call returns Nothing-function call |
Args |
Array |
If the function parameter is listed in the function. If the referenced file name is listed in the referenced files |
For Example One:
class Hello{ Private $var; Public $var 2;protected $var 3; Public function __construct($var,$var 2,$var 3){ $this-var=$var;$this->var2=$var 2;$this->var3=$var 3; } } function test(Hello $hello){ Echo "Hi This is a test function"."<br>"; Print_r (Debug_backtrace ());}$hello 2=NewHello (' A ',' B ',' C '); Test ($hello 2);
The example one outputs the following results:
Hi This is a test function
Array ([0] = = Array (
[File] = D:\www\MyProjecttest\index4.php
[Line] = 52
[Function] = Test
[Args] = Array ([0] = = Hello Object ([var:Hello:private] = A [VAR2] = B [var3:protected] = C))))
Note: Only four parameters are output here: File,line,function,args;
For Example:
class Hello{ Private $var; Public $var 2;protected $var 3; Public function __construct($var,$var 2,$var 3) {
$this-var=$var;$this->var2=$var 2;$this->var3=$var 3; } function test(Hello $hello){ Echo "Hi This is a test function"."<br>"; Print_r (Debug_backtrace ()); }}$hello 2=NewHello (' A ',' B ',' C ');$hello 2->test ($hello 2);
The result of the example output is as follows:
Hi This is a test function
Array ([0] = = Array (
[File] = D:\www\MyProjecttest\index4.php
[Line] = 54
[Function] = Test
[Class] = Hello
[Object] = Hello object ([var:Hello:private] = A [VAR2] = B [var3:protected] + C)
[Type] =
[Args] = Array ([0] = = Hello Object ([var:Hello:private] = A [VAR2] = B [var3:protected] = C))))
Note: In this all parameters are output, respectively: File,line,function,class,object,type,args;
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
PHP Debug_backtrace () function