Home  >  Article  >  Backend Development  >  How to use PHP error handling function debug_backtrace()?

How to use PHP error handling function debug_backtrace()?

藏色散人
藏色散人Original
2019-03-09 14:18:492559browse

How to use PHP error handling function debug_backtrace()?

php debug_backtrace() function is used to generate a PHP backtrace, that is, to generate a PHP backtrace (backtrace).

Syntax:

debug_backtrace(provide_object)

Parameters:

provide_object: Specify whether to fill the object index. The type of provide_object is boolean.

Return value:

The debug_backtrace() function returns an associative array. The following list is the possible returned elements:

## functionstringThe name of the current function. lineintegerCurrent line number. filestringCurrent file name. classstringCurrent class nameobjectobjectCurrent object name. typestringargsarray
Name Type Description
Specifies the current call type.

is used for method calls. (returns "->")

is used for static method calls. (Return "::")

is used for function calls. (If nothing is returned, it is empty)

If inside the function. (This lists the function parameters.)

If in an included file. (This lists the included file names.)

Code example:


<?php
function demo($str)
{
    echo "正在学习:".$str."<br />";
    var_dump(debug_backtrace());
}
demo(&#39;php&#39;);

Output:


正在学习:php
array (size=1)
  0 => 
    array (size=4)
      &#39;file&#39; => string &#39;D:\wamp\www\test\demo.php&#39; (length=25)
      &#39;line&#39; => int 7
      &#39;function&#39; => string &#39;demo&#39; (length=4)
      &#39;args&#39; => 
        array (size=1)
          0 => &string &#39;php&#39; (length=3)

Related recommendations: "

PHP Tutorial"

This article introduces the PHP error handling function debug_backtrace(). I hope it will be helpful to friends in need!

The above is the detailed content of How to use PHP error handling function debug_backtrace()?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn