PHP Function Of The Day: debug_backtrace()

Posted by Dan on 29 Sep 2010 14:15:25

The PHP manual is pretty brief about this function: debug_backtrace — Generates a backtrace, but this is some understatement! This function, debug_backtrace is actually a very powerful function not only when it comes to debugging but also when it comes to writing good clean code.

We all know that functions (and objects) make the life of any developer much easier. With this function, you are given a comprehensive, well, debug backtrace, at the point of calling. Throw into the combination a good bit of variable variables and this function proves to be invaluable at writing short, good, clean code.

"Variable variables and good code in the same sentence!?" I hear you cry! Yes, I was a sceptic at first, but variable variables are actually incredibly powerful and like with most programming methods, when done properly, can really help optimise your code, making it not only more readable but even easier to update.

Using a combination of debug_backtrace() and variable variables (or functions) The class that I am currently working on to integrate into a third party API doesn't have a single line of duplicate code, and I am 100% confident that should this class ever be modified by a team of developers, they would have absolutely no problem finding their way around, adding functionality or updating functionality!

Check it out today: debug_backtrace() on the PHP manual pages: