PHP debug_backtrace 函数

WBOY
Libérer: 2016-07-30 13:30:20
original
1162 Les gens l'ont consulté

PHP debug_backtrace() 函数生成一个 backtrace

该函数返回一个关联数组。

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

For Example one:

<code><span><span>class</span><span>Hello</span>{</span><span>private</span><span>$var</span>;
        <span>public</span><span>$var2</span>;
        <span>protected</span><span>$var3</span>;

    <span>public</span><span><span>function</span><span>__construct</span><span>(<span>$var</span>,<span>$var2</span>,<span>$var3</span>)</span>{</span><span>$this</span>-><span>var</span>=<span>$var</span>;
            <span>$this</span>->var2=<span>$var2</span>;
            <span>$this</span>->var3=<span>$var3</span>;
        } 
   }


<span><span>function</span><span>test</span><span>(Hello <span>$hello</span>)</span>{</span><span>echo</span><span>"Hi this is a test function"</span>.<span>"<br>"</span>;
        print_r(debug_backtrace());
}

<span>$hello2</span>=<span>new</span> Hello(<span>'A'</span>,<span>'B'</span>,<span>'C'</span>);
test(<span>$hello2</span>);</code>
Copier après la connexion

实例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:

<code><span><span>class</span><span>Hello</span>{</span><span>private</span><span>$var</span>;
        <span>public</span><span>$var2</span>;
        <span>protected</span><span>$var3</span>;

   <span>public</span><span><span>function</span><span>__construct</span><span>(<span>$var</span>,<span>$var2</span>,<span>$var3</span>)</span>                   {</span><span>$this</span>-><span>var</span>=<span>$var</span>;
      <span>$this</span>->var2=<span>$var2</span>;
      <span>$this</span>->var3=<span>$var3</span>;
 } 

   <span><span>function</span><span>test</span><span>(Hello <span>$hello</span>)</span>{</span><span>echo</span><span>"Hi this is a test function"</span>.<span>"<br>"</span>;
       print_r(debug_backtrace());
   }
}

<span>$hello2</span>=<span>new</span> Hello(<span>'A'</span>,<span>'B'</span>,<span>'C'</span>);
<span>$hello2</span>->test(<span>$hello2</span>);
</code>
Copier après la connexion

实例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;

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

以上就介绍了PHP debug_backtrace 函数,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Étiquettes associées:
source:php.cn
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal