debug_backtrace
(PHP 4 >= 4.3.0, PHP 5)
debug_backtrace — Genera una backtrace
Descrizione
array debug_backtrace
( void
)
debug_backtrace() genera una backtrace PHP e restituisce questa informazione sotto forma di array associativo. Gli elementi che possono venire restituiti sono elencati nella seguente tabella:
Nome | Tipo | Descrizione |
---|---|---|
funzione | string | Il nome della funzione corrente. Vedere anche __FUNCTION__. |
riga | integer | Il numero della linea corrente. Vedere anche __LINE__. |
file | string | Il nome del file corrente. Vedere anche __FILE__. |
classe | string | Il nome della class corrente. Vedere anche __CLASS__ |
tipo | string | Il tipo di chiamata corrente. Se chiamata di metodo, viene restituito "->" is returned. Se chiamata di metodo statico, viene restituito "::". Se chiamata di funzione, non viene restituito niente. |
args | array | Se all'interno di una funzione, elenca gli argomenti della funzione. Se all'interno di un file incluso, elenca i nomi del file incluso. |
Di seguito un semplice esempio.
Example#1 debug_backtrace() example
<?php
// filename: a.php
function a_test($str)
{
echo "\nHi: $str";
var_dump(debug_backtrace());
}
a_test('friend');
?>
<?php
// filename: b.php
include_once '/tmp/a.php';
?>
Risultati durante l'esecuzione di /tmp/b.php:
Hi: friend array(2) { [0]=> array(4) { ["fp> Risultati durante l'esecuzione di /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" } }
Vedere anche trigger_error() and debug_print_backtrace().