PHP
  Home arrow PHP arrow Page 3 - Debugging Program Flow 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

Debugging Program Flow with the Xdebug Extension
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 4
    2009-02-23


    Table of Contents:
  • Debugging Program Flow with the Xdebug Extension
  • Review: getting information about PHP objects with the var_dump() function
  • Debugging program flow with the xdebug_start_code_coverage() and xdebug_get_code_coverage() functions
  • Using the xdebug_start_code_coverage() and xdebug_get_code_coverage() functions with a basic class

  • 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


    Debugging Program Flow with the Xdebug Extension - Debugging program flow with the xdebug_start_code_coverage() and xdebug_get_code_coverage() functions
    ( Page 3 of 4 )

    As I anticipated in the section that you just read, the X-debug extension provides two handy functions, called “xdebug_start_code_coverage()” and “xdebug_get_code_coverage().” When used in conjunction, these functions allow us to keep track of which lines are executed by a PHP application.

    Naturally, to grasp more easily how these functions work, you should take a look at the following code sample. It creates a simple loop with a “for” PHP statement, and then displays the sequence of program lines that have been executed. Here’s the code sample in question:

    xdebug_start_code_coverage();

    function displayIntegers(){

    for($i=1;$i<=10;$i++){

    echo $i;

    }

    }

    displayIntegers();

    var_dump(xdebug_get_code_coverage());

    /* displays the following

    12345678910


    array

    'pathtoexampleflow_debugging_example.php' =>

    array

    4 => int 1

    5 => int 1

    6 => int 1

    7 => int 1

    8 => int 1

    9 => int 1

    10 => int 1

    */


    As shown in the above example, the pair of “xdebug_start_code_coverage()” and “xdebug_get_code_coverage()” functions permits us to determine with relative ease the program flow of a PHP script. In this case, the tracking process is started with the “xdebug_start_code_coverage()” function, and finalized with its counterpart, “xdebug_get_code_coverage().”

    Undoubtedly, using the previous functions for debugging the execution flow of a specified PHP program should be pretty simple to understand for you, since this is pretty much a no-brainer process. 

    Okay, at this stage, you hopefully grasped the logic that stands behind utilizing the  “xdebug_start_code_coverage()” and “xdebug_get_code_coverage()” functions to determine the execution sequence of a PHP program.

    However, it would be interesting to see how these functions can be used when a script calls different methods of a class. Therefore, in the last section of this tutorial I’ll be coding an example that will represent this particular situation.

    To see how this last practical example will be developed, please click on the link that appears below and keep reading.



     
     
    >>> 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 4 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek