Home arrow PHP arrow Page 3 - Debugging Program Flow with the Xdebug Extension

Debugging program flow with the xdebug_start_code_coverage() and xdebug_get_code_coverage() functions - PHP

The Xdebug PHP extension combines a set of powerful functions with an easy learning curve. This appealing mixture turns it into the choice of many PHP developers for debugging PHP applications with a great level of detail. If you want to learn how to get the most out of this debugging library without having to spend long hours reading its user manual, then keep reading. In this seven-part series of articles you’ll find an approachable guide to utilizing its most important functions. I will use numerous code samples to instruct you in the use of the Xdebug extension.

TABLE OF CONTENTS:
  1. Debugging Program Flow with the Xdebug Extension
  2. Review: getting information about PHP objects with the var_dump() function
  3. Debugging program flow with the xdebug_start_code_coverage() and xdebug_get_code_coverage() functions
  4. Using the xdebug_start_code_coverage() and xdebug_get_code_coverage() functions with a basic class
By: Alejandro Gervasio
Rating: starstarstarstarstar / 4
February 23, 2009

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

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
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: