PHP
  Home arrow PHP arrow Page 2 - 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 - Review: the xdebug_start_code_coverage() and xdebug_get_code_coverage() functions
    ( Page 2 of 4 )

    Before I start explaining how to use the “xdebug_start_code_coverage()” and “xdebug_get_code_coverage()” functions to debug conditional statements within a PHP application, I’m going to reintroduce the last example that I created in the preceding tutorial. It was aimed at illustrating how to utilize the same functions for keeping track of which lines were executed by a simple function and a sample class.

    The code samples corresponding to these practical examples originally looked like this:

    (example on debugging program flow with a PHP function)


    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

    */



    (example on debugging program flow with a PHP class)


    class User{

    private $firstName;

    private $lastName;

    private $email;

    public function __construct($firstName,$lastName,$email){

    if(!$firstName){

    throw new Exception('Invalid parameter First Name.');

    }

    if(!$lastName){

    throw new Exception('Invalid parameter Last Name.');

    }

    if(!$email){

    throw new Exception('Invalid parameter Email.');

    }

    $this->firstName=$firstName;

    $this->lastName=$lastName;

    $this->email=$email;

    }

    // get first name

    public function getFirstName(){

    return $this->firstName;

    }

    // get last name

    public function getLastName(){

    return $this->lastName;

    }

    // get email

    public function getEmail(){

    return $this->email;

    }

    }


    try{

    xdebug_start_code_coverage();

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

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

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

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

    var_dump(xdebug_get_code_coverage());

     

    /* displays the following

    First Name :John

    Last Name :Doe

    Email :john@domain.com

    array

    'pathtoexampleflow_debugging_example.php' =>

    array

    8 => int 1

    11 => int 1

    14 => int 1

    17 => int 1

    18 => int 1

    19 => int 1

    20 => int 1

    23 => int 1

    27 => int 1

    31 => int 1

    36 => int 1

    37 => int 1

    38 => int 1

    39 => int 1

    41 => int 1

    */

    }

    catch(Exception $e){

    echo $e->getMessage();

    exit();

    }


    As illustrated above, the combination of the “xdebug_start_code_coverage()” and “xdebug_get_code_coverage()” functions is very convenient for determining the program flow of a PHP script. In the first example, these functions are used in conjunction to determine the sequence of lines that are executed by a simple PHP function, while in the second case, this same process is applied to a primitive class.

    At this point, I’m pretty sure that you have already grasped the logic that drives the two previous code samples, since they’re very easy to follow. With that idea in mind, it’s time to continue exploring the  functionality provided by the “xdebug_start_code_coverage()” and “xdebug_get_code_coverage()” functions.

    Thus, as I expressed in the introduction, it would be quite useful to demonstrate how these functions can be used with conditional statements. In the upcoming section I’ll be coding a brand new example, which hopefully will demonstrate how to utilize these functions with a simple conditional instruction.

    As usual, to see how this example will be developed, please click on the link shown 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 3 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek