debug_backtrace

(PHP 4 >= 4.3.0, PHP 5)

debug_backtrace --  Gera um backtrace

Descrição

array debug_backtrace ( void )

debug_backtrace() gera um backtrace e retorna esta informação em uma matriz associativa. Os elementos possivelmente retornados estão na seguinte tabela:

Tabela 1. Elementos possivelmente retornados de debug_backtrace()

NomeTipoDescrição
functionstring O nome da função atual. Veja também __FUNCTION__.
lineinteger O número da linha atual. Veja também __LINE__.
filestring O nome do arquivo atual. Veja também __FILE__.
classstring O nome da classe atual. Veja também __CLASS__.
typestring O tipo da chamada atual. Se for uma chamada a metodo, é retornado "->". Se for uma chamada a um metodo estatico, é retornado "::". Se é uma chamada a uma função, não é retornado nada.
argsarray Se estiver dentro de uma função, lista os argumentos da função. Se estiver dentro de um arquivo incluído, lista o(s) nome(s) do(s) arquivo(s).

A seguir esta um exemplo simples.

Exemplo 1. Exemplo debug_backtrace()

<?php
// nome do arquivo: a.php

function a_test($str)
{
    echo
"\nHi: $str";

    
var_dump(debug_backtrace());
}

a_test('friend');
?>


<?php
// nome do arquivo: b.php
include_once '/tmp/a.php';
?>

Resultados quando executando /tmp/b.php:

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"
  }
}

Veja também trigger_error() e debug_print_backtrace().