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.

TABLE OF CONTENTS:
  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
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

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(){

var_dump(xdebug_get_function_stack());

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
   

PHP ARTICLES

- 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...
- PHP: Building Concrete Validators
- Sanitizing Input with PHP
- Executing Shell Commands with PHP
- Handling File Data with PHP
- File Security and Resources with PHP
- ArrayObject PHP Class Examples
- ArrayObject PHP Class: An Introduction
- Getting File System Data with PHP
- PHP Tools for Working with the File and Oper...
- Working with the File and Operating System w...
- PHP Proxy Patterns: Completing a Blog


© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 9 - Follow our Sitemap

Dev Shed Tutorial Topics: