PHP
  Home arrow PHP arrow Page 4 - Working with the X-debug extension`s var_dump() function
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

Working with the X-debug extension`s var_dump() function
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 2
    2009-02-17


    Table of Contents:
  • Working with the X-debug extension`s var_dump() function
  • Review: the xdebug_call_function() method
  • Using the enhanced version of the var_dump() PHP function
  • Retrieving information about a PHP object with the var_dump() function

  • 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


    Working with the X-debug extension`s var_dump() function - Retrieving information about a PHP object with the var_dump() function
    ( Page 4 of 4 )

    Since the "var_dump()" function accepts any type of PHP variable as an incoming parameter, it permits you to retrieve meaningful information about objects as well. Of course, this feature can be quite useful when developing and debugging applications that use the object-oriented paradigm, so if you create PHP programs that rely on classes for doing their business, then you'll find the "var_dump()" function fairly appealing.

    However, it's necessary to develop an example that demonstrates how this function actually works when utilized on a specified object. So, to do that I'm going to use the same sample "User" class that you saw in the beginning, whose signature looked like this:


    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;

    }

    }


    Now that there's a basic class available for testing purposes, it's time to pass to the "var_dump()" function an instance of it, so you can see clearly how it retrieves useful information about a simple object. The following code sample feeds the function a trivial array that also includes an object spawned from the above "User" class. Take a look at it:


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

    }


    Not too bad, right? As you can see in the above example, the "var_dump()" function returns detailed information to client code about the $user object passed in as an incoming argument. It displays the name of the originating class, along with the values and lengths (expressed in characters) assigned to the object's properties.

    With this particular example, it's clear to see how the X-debug library extends the functionality of the "var_dump()" PHP built-in function. If you debug your programs' variables by means of this function, then its enhanced version will put a big smile in your face.

    Final thoughts

    Over this third part of the series, I provided you with a quick overview of the improved version of the PHP native "var_dump()" function included with the X-debug extension. As you saw, it can be really useful for debugging program variables with a greater level of detail.

    In the forthcoming installment, I'll be exploring the set of functions bundled with X-debug that permit you to keep track of each line executed by a PHP script. Do you want to learn how these functions work? Then don't miss the next article!



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