Monday 26 August 2013

PHP Function debug_backtrace()

Syntax

array debug_backtrace ( void );

Definition and Usage

Returns an associative array. The possible returned elements are as follows:
NameTypeDescription
functionstringThe current function name.
lineintegerThe current line number.
filestringThe current file name.
classstringThe current class name.
objectstringThe current Object.
typestringThe current call type. If a method call, "->" is returned. If a static method call, "::" is returned. If a function call, nothing is returned.
argarrayIf inside a function, this lists the functions arguments. If inside an included file, this lists the included file name(s).

Paramters

ParameterDescription
voidNA.

Return Value

Returns an associative array as described in the description.

Example

Following is the usage of this function:
<?php
function printStr($str)
{
    echo "Hi: $str";
    var_dump(debug_backtrace());
}

printStr('friend');
?> 
This will produce following result:
Hi: friendarray(1) {
  [0]=>
  array(4) {
    ["file"]=> string(36) "/var/www/tutorialspoint/php/test.php"
    ["line"]=> int(8)
    ["function"]=> string(8) "printStr"
    ["args"]=> array(1) {
                             [0]=>
                             &string(6) "friend"
                           }
  }
}

No comments:

Post a Comment