PHP
  Home arrow PHP arrow Page 4 - Tracking a Stack of Function Calls with the Xdebug Extension
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
Google.com  
PHP

Tracking a Stack of Function Calls with the Xdebug Extension
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 2
    2009-03-16


    Table of Contents:
  • Tracking a Stack of Function Calls with the Xdebug Extension
  • Review: the xdebug_time_index() function
  • Retrieving information with the xdebug_get_function_stack() function
  • Displaying the contents of the stack of function calls

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Tracking a Stack of Function Calls with the Xdebug Extension - Displaying the contents of the stack of function calls
    ( Page 4 of 4 )

    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
     

       

    PHP ARTICLES

    - Adding Ordering and Grouping Clauses to the ...
    - Implementing Factory Methods in PHP 5
    - Merging a File Split for FTP Upload using PHP
    - Getting Data from Yahoo Site Explorer Inboun...
    - Method Chaining: Adding More Selecting Metho...
    - How to Split a File During an FTP Upload Usi...
    - Expanding a Custom CodeIgniter Library with ...
    - Using the Yahoo Site Explorer Inbound Links ...
    - Building a CodeIgniter Custom Library with M...
    - Building an E-mini Trading System Using PHP ...
    - Completing the MySQL Class with Method Chain...
    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek