PHP
  Home arrow PHP arrow Page 4 - Using Conditional Statements 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

Using Conditional Statements with the Xdebug Extension
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 2
    2009-03-02


    Table of Contents:
  • Using Conditional Statements with the Xdebug Extension
  • Review: the xdebug_start_code_coverage() and xdebug_get_code_coverage() functions
  • Extending the xdebug_start_code_coverage() and xdebug_get_code_coverage() functions
  • Debugging conditionals with the xdebug_start_code_coverage() and xdebug_get_code_coverage() functions

  • 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


    Using Conditional Statements with the Xdebug Extension - Debugging conditionals with the xdebug_start_code_coverage() and xdebug_get_code_coverage() functions
    ( Page 4 of 4 )

    To complete the practical example developed in the prior section, it’s necessary to show the output produced by the script when the “rand()” PHP function returns a value greater than five to client code.

    In that particular case, the “xdebug_start_code_coverage()” and “xdebug_get_code_coverage()” functions will display on screen the sequence of lines being executed within the second block of code, instead of the instructions wrapped in the first one.

    But undoubtedly, this process will be better understood if you examine the following code sample, which represents this situation in a clear manner:

    xdebug_start_code_coverage();

    $user=new User('John','Doe','john@domain.com');

    if(rand(1,10)<5){

    echo 'First Name :'.$user->getFirstName().'<br />';

    echo 'Last Name :'.$user->getLastName().'<br />';

    }

    else{

    echo 'Email :'.$user->getEmail().'<br />';

    }

    var_dump(xdebug_get_code_coverage());



    /* displays the following when the 'rand()' function returns a value > 5


    Email :john@domain.com


    array

     '/path/to/example/program_flow_debug.php' =>

    array

    8 => int 1

    11 => int 1

    14 => int 1

    17 => int 1

    18 => int 1

    19 => int 1

    20 => int 1

    31 => int 1

    36 => int 1

    37 => int 1

    42 => int 1

    44 => int 1

    */


    Definitely, the example shown above should be extremely simple for you to grasp. All it does is show the output generated by the xdebug_start_code_coverage()” and “xdebug_get_code_coverage()” functions when the second block of code is executed by the previous script. See how easy it is to use these functions along with conditional statements to keep track of the flow followed by a PHP application? I bet you do!

    The best way to grasp how those functions do their work, however, is with lots of practice. Thus, feel free to tweak all of the code samples included in this tutorial, so you can acquire a more solid background in using these handy functions provided by the Xdebug extension.

    Final thoughts


    In this fifth chapter of the series, I walked you through using the "xdebug_start_code_coverage()” and “xdebug_get_code_coverage()” functions, which can be really useful for debugging execution flow of a PHP application.

    However, this educational journey of exploring the Xdebug library hasn’t finished yet, since it includes a few other functions that deserve a close analysis. Therefore, in the next article I’ll be taking a look at the “xdebug_index_time()” function, which can be used for benchmarking PHP scripts very easily.

    This is my little piece of advice: don’t miss the upcoming 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 2 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek