PHP
  Home arrow PHP arrow Page 2 - 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 - Review: getting information about PHP objects with the var_dump() function
    ( Page 2 of 4 )

    Before I start explaining how to use the aforementioned “xdebug_start_code_coverage()” and “xdebug_get_code_coverage()” functions, I will quickly review the practical example created in the preceding article of this series. It demonstrated how to retrieve relevant information about a specified object through the “var_dump()” function.

    Basically, the entire source code of the example in question looked like this:

    (example on using the 'var_dump()' function with a sample array)


    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{

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

    $data=array('string'=>'This is a string','integer'=>1,'float'=>0.123456,'object'=>$user);

    var_dump($data);

     

    /* displays the following

    array

    'string' => string 'This is a string' (length=16)

    'integer' => int 1

    'float' => float 0.123456

    'object' =>

    object(User)[1]

    private 'firstName' => string 'John' (length=4)

    private 'lastName' => string 'Doe' (length=3)

    private 'email' => string 'john@domain.com' (length=15)

    */

    }

    catch(Exception $e){

    echo $e->getMessage();

    exit();

    }


    As shown above, the “var_dump()” function can be very helpful for retrieving information about a group of specified variables, since its functionality has been extended when used with the Xdebug library. In this specific case, the function has been fed with a basic array of elements, where one of them is an instance of the “User” class listed before.

    Aside from retrieving the name of the object passed as an incoming argument, the function also returns a few other helpful values. These include the name of its properties and the corresponding length expressed in characters.

    At this stage, and having already reviewed how the “var_dump()” function does its thing, it’s time to explore more functions that come bundled with the Xdebug extension. Thus, as I explained in the introduction, the library allows you to follow the flow of a specified application by means of the “xdebug_start_code_coverage()” and “xdebug_get_code_coverage()” functions.

    Thus, in the upcoming section I’ll be coding a brand new example. It will demonstrate how to use these functions to determine which lines are executed by a PHP program.

    Click on the link below and keep reading, please.



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