I’m finding that sometimes debug_backtrace() is not including the line number for a call. Is there some reason why this is and any way to correct for it?
Thanks in advance.
P.S. And yes, the calls that it is omit line numbers for are my own code, not internal PHP code.
Consider following code:
The execution of above example generates following output:
The first backtrace item (index 0) says indirectly (through the
lineandfileitems) that thegetTheItemmethod was called from the__callmethod.The second backtrace item (index 1) says that the
__callmethod was called from somewhere (missinglineandfileitems).The third backtrace item (index 2) says that the
testmethod was called from the global scope of the script.The place of the
__callmethod call is probably in some method resolution code somewhere in the php interpreter code. There are two possibilities of fixing it. Either the second item should refer interpreter’s source code file and line or the second and the third backtrace items should be merged into one. I personally would prefer the second solution as the interpreter’s internals are not interesting for me (this is how they seem to do it in python’s traceback), however I understand that sometimes the first solution provides more explicit trace (especially when it’s a callback which is called from the internals).So or so, it seems that the developer(s) responsible for (or at least maintaining) the code of the
debug_backtracefunction doesn’t perceive it as a bug or maybe has no easy way to fix it. It would be ok to fill thelineandfileitems with some place holder values (e.g.<unknown-file>and0or even nulls) and emphasize it in the documentation. Unless someone will successfully convince them to do it, you just have to handle the special case in your code.I wrote above just to share my understanding of the strange behaviour of the function. If someone has a willingness to fight for a slightly better world, here are links to some related bug reports:
__FILE__,__LINE__The oldest report is from 2003, so you shouldn’t count on a fast fix 🙂