Recent Blog Posts
Blogs ยป Archive for March 7th, 2004
Whodunnit
Ever needed to know who called that function or class method resulting in your app going horribly wrong? Try debug_backtrace().
Dropping this in the function where the problem was found, you get to see the call stack which led up to the function call.
The call stack is essentially all the currently active functions / methods which have not yet returned to the point where they were called. It’s easiest to see by example.
Let’s say there’s some code you have where one function calls another which calls another like;
So if displayMessage() is called, it calls formatName() which itself calls hello() (OK this is a dumb example but illustrates the point).
Now a simple controller for the above functions;
if ( isset($_GET[’name’]) ) {
displayMessage($_GET[’name’]);
} else {
?>
Enter your name
So far so good. But let’s say in a few weeks, you modify the formatName() function and, by mistake, insert a bug;
function formatName($name) {
$name = strtolower($name);
if ($name == ‘ted’) {
$name .= ‘ (nice to see you)’;
} else {
…
Sponsored Links
SitePoint Marketplace
Buy and sell Websites, templates, domain names, hosting, graphics and more.
Download sample chapters of any of our popular books.




