Regardless of any "bug", "feature", whatever the folks who maintain PHP would like to say, the debug_backtrace() does not work as I would expect.
Here is my solution (it is ugly, but it works for me):
function dbg($msg="") { ob_start(); debug_print_backtrace(0,1); $_ = ob_get_clean(); list($ignore,$line_number) = explode(':', $_); $line_number += 0; $backtrace = debug_backtrace(0); extract($backtrace[1]); echo "<pre>$class::$function($msg) : $line_number</pre>"; }
The PHP function debug_print_backtrace(0,1); will produce something like this:
#0 dbg->ping(290) called at[/path/to/filename.php:290]
Since it only echos the trace, I have to ob_get_clean() it as a string. Then I parse it.
In my implementation, I only want to know the class, function, line number, and, optionally, a string message from the calling function. debug_backtrace() provides class and function correctly, but not line-number. That is why I have to get the line number from the debug_print_backtrace() function.
For bonus points.... how is it that debug_print_backtrace() function "knows" the line number, but debug_backtrace() [occasionally] does not, eh??? ... it's a mystery...