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

Displaying the contents of the stack of function calls - 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

In the previous section, I built a simple decorative class that added a few star characters to an inputted string. The most relevant aspect of this class, however, is obviously that it employs internally the “xdebug_get_function_stack()” function, meaning that it’s necessary to code a short example that demonstrates its functionality.

Therefore, below I included a simple code sample. It shows the output generated by this function when called from inside the “NameDecorator” class:

$nameDec=new NameDecorator();

$nameDec->displayDecoratedName(array('John','Mary','Susan'));


/* displays the following

array

0 =>

array

'function' => string '{main}' (length=6)

'file' => string '/path/to/example/stack_call_example.php' (length=72)

'line' => int 0

'params' =>

array

empty

1 =>

array

'function' => string 'displayDecoratedName' (length=20)

'class' => string 'NameDecorator' (length=13)

'file' => string '/path/to/example/stack_call_example.php' (length=72)

'line' => int 15

'params' =>

array

empty

2 =>

array

'function' => string 'displayStars' (length=12)

'class' => string 'NameDecorator' (length=13)

'file' => string '/path/to/example/stack_call_example.php' (length=72)

'line' => int 10

'params' =>

array

empty


********** John


array

0 =>

array

'function' => string '{main}' (length=6)

'file' => string '/path/to/example/stack_call_example.php' (length=72)

'line' => int 0

'params' =>

array

empty

1 =>

array

'function' => string 'displayDecoratedName' (length=20)

'class' => string 'NameDecorator' (length=13)

'file' => string '/path/to/example/stack_call_example.php' (length=72)

'line' => int 15

'params' =>

array

empty

2 =>

array

'function' => string 'displayStars' (length=12)

'class' => string 'NameDecorator' (length=13)

'file' => string '/path/to/example/stack_call_example.php' (length=72)

'line' => int 10

'params' =>

array

empty


********** Mary


array

0 =>

array

'function' => string '{main}' (length=6)

'file' => string '/path/to/example/stack_call_example.php' (length=72)

'line' => int 0

'params' =>

array

empty

1 =>

array

'function' => string 'displayDecoratedName' (length=20)

'class' => string 'NameDecorator' (length=13)

'file' => string '/path/to/example/stack_call_example.php' (length=72)

'line' => int 15

'params' =>

array

empty

2 =>

array

'function' => string 'displayStars' (length=12)

'class' => string 'NameDecorator' (length=13)

'file' => string '/path/to/example/stack_call_example.php' (length=72)

'line' => int 10

'params' =>

array

empty


********** Susan

*/


That was pretty interesting, right? As you can see, once the above “NameDecorator” class was fed with an input array comprised of a few trivial names, it echoed to the browser not only their decorated versions, but another array containing relevant information about the script being executed -- including the file name and program lines being parsed, and the stack of functions called by the class.

Considering that all of this data was generated by the ““xdebug_get_function_stack()” function, it’s fair to say that it can be really helpful for debugging PHP applications with minor efforts.

With this final example I’m finishing this introductory guide to using the Xdebug extension. Since this library includes a lot of other functions, my suggestion is that you read its official documentation for full information on each of them. Happy debugging!

Final thoughts

It’s hard to believe, but we've finally come to the end of this series. Overall, the experience has been both fun and instructive, since you learned how to install the Xdebug extension and how to use its most relevant functions.

As you saw through the code samples created in the articles, the library is pretty intuitive. Best of all, it provides detailed information about common aspects of a PHP program, which can be really helpful for performing debugging tasks that require a great deal of detailed information.

See you in the next PHP web development tutorial!



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

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- 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: