• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

PHP debug_backtrace() 函数

php 搞代码 4年前 (2022-01-23) 26次浏览 已收录 0个评论

PHP debug_backtrace() 函数生成一个 backtrace

该函数返回一个关联数组

下面是可能返回的元素
function 字符串 当前的函数名
line 整数 当前的行号
file 字符串 当前的文件名
object 对象 当前对象
type 字符串 当前的调用类型,可能的调用: 返回: “->” – 方法调用返回: “::” – 静态方法调用返回 nothing – 函数调用
args 数组 如果在函数中,列出函数参数。如果在被引用的文件中,列出被引用的文件名

For Example one:

 class Hello{        private    $var;        public     $var2;        protected  $var3;    public function __construct($var,$var2,$var3){            $this->var=$var;            $this->var2=$var2;            $this->var3=$var3;        }    }function test(Hello $hello){        echo "Hi this is a test function"."<br>";        print_r(debug_backtrace());}$hello2=new Hello('A','B','C');test($hello2);

实例One输出结果如下:

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

注:在此只输出四个参数,分别是:file,line,function,args;

For Example Two:

class Hello{        private    $var;        public     $var2;        protected  $var3;   public function __construct($var,$var2,$var3) {      $this->var=$var;      $this<i>*本5文来源gaodai$ma#com搞$$代**码)网@</i><img>搞代码gaodaima</img>->var2=$var2;      $this->var3=$var3; }    function test(Hello $hello){       echo "Hi this is a test function"."<br>";       print_r(debug_backtrace());   }}$hello2=new Hello('A','B','C');$hello2->test($hello2);

实例Two输出结果如下:

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

注:在此所有参数都输出了,分别是:file,line,function,class,object,type,args;

版权声明:本文为博主原创文章,未经博主允许不得转载。


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:PHP debug_backtrace() 函数
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址