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

Review: getting information about PHP objects with the var_dump() function - 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.

  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



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


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



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



throw new Exception('Invalid parameter 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;




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

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



/* displays the following


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

'integer' => int 1

'float' => float 0.123456

'object' =>


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();



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

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


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