Home  >  Article  >  Backend Development  >  About the debug_backtrace() function in PHP that prints debugging information at the call location

About the debug_backtrace() function in PHP that prints debugging information at the call location

不言
不言Original
2018-07-14 17:09:021910browse

This article mainly introduces the debugging information about the debug_backtrace() function print call in PHP. It has a certain reference value. Now I share it with you. Friends in need can refer to it

debug_backtrace

(PHP 4 >= 4.3.0, PHP 5, PHP 7)

debug_backtrace — Generate a backtrace

Description

##array debug_backtrace ([ int $options = DEBUG_BACKTRACE_PROVIDE_OBJECT [, int $limit = 0 ]] )

#debug_backtrace () Generates a PHP backtrace.

Parameters

  • options

  • As of 5.3.6, this parameter is the following Bit mask of options:
  • debug_backtrace() optionDEBUG_BACKTRACE_PROVIDE_OBJECTDEBUG_BACKTRACE_IGNORE_ARGSBefore 5.3.6, the only values ​​that could be used were
    Whether to fill in "object" index.
    Whether to ignore the index of "args", including all function/method parameters, can save memory overhead.
    TRUE

    or FALSE, which were respectively equal to whether to set DEBUG_BACKTRACE_PROVIDE_OBJECT option.

  • limit

  • As of 5.4.0, this parameter can be used to limit the number of stack frames returned. The default is (
  • limit

    =0), which returns all stack frames.

  • Return value

Returns an

array containing many associative arrays. Elements that may be returned:

Elements that may be returned from debug_backtrace()NamefunctionstringlineintegerfilestringclassstringobjectobjecttypestringargsarrayUpdate Log
Type Description
The current function name, see: __FUNCTION__.
The current line number. See: __LINE__.
The current file name. See: __FILE__.
The name of the current class. See __CLASS__
the current object.
The type of the current call. If it is a method, "->" will be returned. If it is a static method, "::" will be returned. If it is a function call, returns null.
If inside a function, this will list the parameters of the function. If it is in an included file, the included file name will be listed.

Version5.4.0limit5.3.6provide_object5.2.5Added optional parameter . 5.1.1Added the current

Example

Example #1 debug_backtrace() Example

<?php
// filename: /tmp/a.php
function a_test($str)
{
    echo "\nHi: $str";
    var_dump(debug_backtrace());
}
a_test(&#39;friend&#39;);
?>
<?php
// filename: /tmp/b.php
include_once &#39;/tmp/a.php&#39;;
?>

Execution The result returned is similar to the following:

Hi: friend
array(2) {
[0]=>
array(4) {
    ["file"] => string(10) "/tmp/a.php"
    ["line"] => int(10)
    ["function"] => string(6) "a_test"
    ["args"]=>
    array(1) {
      [0] => &string(6) "friend"
    }
}
[1]=>
array(4) {
    ["file"] => string(10) "/tmp/b.php"
    ["line"] => int(2)
    ["args"] =>
    array(1) {
      [0] => string(10) "/tmp/a.php"
    }
    ["function"] => string(12) "include_once"
  }
}

The above is the entire article Content, I hope it will be helpful to everyone’s learning. For more related content, please pay attention to the PHP Chinese website!

Related recommendations:

How to use var_export in PHP

About a problem encountered with PHP conditional operators and Solution

Description
Added optional parameter .
The parameter was changed to options, and the optional parameter DEBUG_BACKTRACE_IGNORE_ARGS# was added ##.
provide_object
object as a possible returned element.

The above is the detailed content of About the debug_backtrace() function in PHP that prints debugging information at the call location. 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