P粉2918868422023-08-01 00:11:59
debug_backtrace()
provides a call stack that can trace where you are, but you are already in the outermost (i.e. global) scope and have not made any calls, so no call stack is available.
print_r(debug_backtrace());
The result produced is:
Array ( )
If you put the code in a function, you will get a call stack containing one item:
function foo() { print_r(debug_backtrace()); } foo();
The result produced is:
Array ( [0] => Array ( [file] => ... [line] => 6 [function] => foo [args] => Array ( ) ) )
If you want to get some (minimal) debugging information in the global scope, you can wrap all the code in a closure and call it inline immediately:
(function() { // all your code here print_r(debug_backtrace()); })();
result
Array ( [0] => Array ( [file] => ... [line] => 5 [function] => {closure} [args] => Array ( ) ) )
Regarding session/environment data, they will only be displayed if you pass them as parameters:
foo($_ENV);
result:
Array ( [0] => Array ( [file] => ... [line] => 6 [function] => foo [args] => Array ( [0] => Array ( [TERM] => xterm [PATH] => /usr/bin:/bin [LANG] => C [SHELL] => /bin/sh [MAIL] => /var/mail/nobody [LOGNAME] => nobody [USER] => nobody [HOME] => /tmp ) ) ) )
If you want to log session/environment variables like this, the best way is probably to output them explicitly:
error_log(print_r($_ENV, true));
error_log(print_r($_SESSION, true));