debug_backtrace回溯跟踪
2014-11-14 00:51
文件:a.php
<?php
class a{
public $name = '';
function a($name){
$this->name = $name;
}
function hello($name){
echo 'hello '.$name;
echo '<pre>';
print_r(debug_backtrace());
echo '</pre>';
}
}
$a = new a("Sony");
$a->hello("Sony");
?>
文件:b.php
<?php
include("a.php");
?>
文件:c.php
<?php
include("b.php");
?>
输出结果:
hello Sony
Array
(
[0] => Array
(
[file] => D:\wamp\www\test\debug_backtrace\a.php
[line] => 15
[function] => hello
[class] => a
[object] => a Object
(
[name] => Sony
)
[type] => ->
[args] => Array
(
[0] => Sony
)
)
[1] => Array
(
[file] => D:\wamp\www\test\debug_backtrace\b.php
[line] => 2
[args] => Array
(
[0] => D:\wamp\www\test\debug_backtrace\a.php
)
[function] => include
)
[2] => Array
(
[file] => D:\wamp\www\test\debug_backtrace\c.php
[line] => 2
[args] => Array
(
[0] => D:\wamp\www\test\debug_backtrace\b.php
)
[function] => include
)
)
结果分析:
debug_backtrace()函数,会生成,从访问的URL到使用debug_backtrace()函数的文件,之间的一条“回溯跟踪线”,这条“线”以多维数组(2维或3维)的形式记录。
其中,一维数组的每个值,可以看做是一个“回溯结点”(一个文件),这些“结点”,以URL到使用此函数的文件倒叙排列,即本URL文件是末尾“结点”(键最大),使用此函数的文件是“开始结点”(键最小为0)。
二维数组,也就是这里说的“结点”。一般具有下列信息:
function string 当前的函数名
line integer 当前的行号
file string 当前的文件名
class string 当前 class 的名称
object object 当前的 object。
type string 当前调用的类型。如果是一个方法,会返回 "->"。如果是一个静态方法,会返回 "::"。 如果是一个函数调用,则返回空。
args array 如果在一个函数里,这会列出函数的参数
三维数组即是“结点”信息中的class, object, args信息。
2014-11-14 00:51
文件:a.php
<?php
class a{
public $name = '';
function a($name){
$this->name = $name;
}
function hello($name){
echo 'hello '.$name;
echo '<pre>';
print_r(debug_backtrace());
echo '</pre>';
}
}
$a = new a("Sony");
$a->hello("Sony");
?>
文件:b.php
<?php
include("a.php");
?>
文件:c.php
<?php
include("b.php");
?>
输出结果:
hello Sony
Array
(
[0] => Array
(
[file] => D:\wamp\www\test\debug_backtrace\a.php
[line] => 15
[function] => hello
[class] => a
[object] => a Object
(
[name] => Sony
)
[type] => ->
[args] => Array
(
[0] => Sony
)
)
[1] => Array
(
[file] => D:\wamp\www\test\debug_backtrace\b.php
[line] => 2
[args] => Array
(
[0] => D:\wamp\www\test\debug_backtrace\a.php
)
[function] => include
)
[2] => Array
(
[file] => D:\wamp\www\test\debug_backtrace\c.php
[line] => 2
[args] => Array
(
[0] => D:\wamp\www\test\debug_backtrace\b.php
)
[function] => include
)
)
结果分析:
debug_backtrace()函数,会生成,从访问的URL到使用debug_backtrace()函数的文件,之间的一条“回溯跟踪线”,这条“线”以多维数组(2维或3维)的形式记录。
其中,一维数组的每个值,可以看做是一个“回溯结点”(一个文件),这些“结点”,以URL到使用此函数的文件倒叙排列,即本URL文件是末尾“结点”(键最大),使用此函数的文件是“开始结点”(键最小为0)。
二维数组,也就是这里说的“结点”。一般具有下列信息:
function string 当前的函数名
line integer 当前的行号
file string 当前的文件名
class string 当前 class 的名称
object object 当前的 object。
type string 当前调用的类型。如果是一个方法,会返回 "->"。如果是一个静态方法,会返回 "::"。 如果是一个函数调用,则返回空。
args array 如果在一个函数里,这会列出函数的参数
三维数组即是“结点”信息中的class, object, args信息。