Home arrow PHP arrow Page 3 - Tracking a Stack of Function Calls with the Xdebug Extension

Retrieving information with the xdebug_get_function_stack() function - PHP

If you’re a PHP programmer looking for a comprehensive guide to using the most relevant functions that come with the X-debug extension, then this set of articles might be what you need. Welcome to the last part of a series focusing on debugging in PHP with the Xdebug extension. In seven approachable parts, this series gets you started utilizing this library's numerous features by way of a hands-on approach.

  1. Tracking a Stack of Function Calls with the Xdebug Extension
  2. Review: the xdebug_time_index() function
  3. Retrieving information with the xdebug_get_function_stack() function
  4. Displaying the contents of the stack of function calls
By: Alejandro Gervasio
Rating: starstarstarstarstar / 2
March 16, 2009

print this article



To show you the use of the “xdebug_get_function_stack()” function as clearly as possible, I’m going to build another sample class. It will be tasked with performing a pretty trivial task -- decorating any string passed in as an incoming argument with a few stars.

Regardless of the simplicity of the logic implemented by this class, it should illustrate how to use the “xdebug_get_function_stack()” function in a specific case.

Here’s the signature corresponding to this sample class, which I dubbed “NameDecorator”:

class NameDecorator{

public function displayStars(){


return str_repeat('*',10);


public function displayDecoratedName($names=array()){

foreach($names as $name){

echo $this->displayStars().' '.$name.'<br />';




Definitely, the signature of the above “NameDecorator” class is pretty easy to follow, isn’t it? As shown before, this class declares and implements only two basic methods. The first one is charged with generating a string composed of ten star characters, which will be added to each name passed in as an input parameter.

This “decorative” process will be performed by the second “displayDecoratedName()” method, which you should grasp in a snap. However, the most important thing to note here is that the class will make use of the “xdebug_get_function_stack()” function to display the content of the stack of function calls.

Now that there’s a sample class available for illustrating how the “xdebug_get_function_stack()” function does its thing, it’s time to create a final example to show you how this function can keep track of the stack of methods called by the “NameDecorator” class.

Wait are you waiting for? Click on the link  below and read the following section.

>>> More PHP Articles          >>> More By Alejandro Gervasio

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates


Dev Shed Tutorial Topics: