PHP
  Home arrow PHP arrow Page 4 - The X-debug 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

The X-debug Extension
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 2
    2009-02-02


    Table of Contents:
  • The X-debug Extension
  • Getting started using the X-debug library
  • Keeping track of file calls with the X-debug extension
  • Working with the xdebug_call_line() 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


    The X-debug Extension - Working with the xdebug_call_line() function
    ( Page 4 of 4 )

    As I mentioned in the previous section, the X-debug extension includes another useful function, called “xdebug_call_line(),” which returns the line number from which a method, function or statement has been invoked.

    To demonstrate how this function works, I’m going to modify the signature of the sample “User” class that you learned before, which now will use the “xdebug_call_line()” function for implementing a brand new method, named “getLine().”

    That being said, here’s the modified signature of the “Users” 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->firstName;

    }

    // get email

    public function getEmail(){

    return $this->email;

    }

    // get line from which this method was called

    public function getLine(){

    return 'Called from line '.xdebug_call_line();

    }

    }


    Here, it’s clear to see how the above “getLine()” method defined within the  “User” class uses the “xdebug_call_line()” function to return to client code the line from which the method in question has been called.

    Does this sound rather confusing? It’s not, really. The sample script shown below should give you a clear idea of how the “xdebug_call_line()” function works. Here it is:


    try{

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

    echo $user->getLine();

     

    /* displays the following

    Called from line 40

    */

    }

    catch(Exception $e){

    echo $e->getMessage();

    exit();

    }


    See how simple it is to utilize the “xdebug_call_line()” function within a sample class? I hope you do! In this specific case, the function returns the line from which the “getLine()” method has been called. Simple and useful too.

    Of course, this function may seem a bit primitive to be used for debugging purposes. But, when combined with the “xdebug_file_call()” function that you saw before, you can get more detailed information on the way that your script works. Try them out for yourself and see how they behave in each case.

    Final thoughts

    In this first chapter of the series, I provided you with a quick introduction to installing and using the X-debug PHP extension for debugging a couple of simple PHP scripts. As I said in the introduction, this extension is pretty simple to configure and use, and these features make it suitable for both beginners and advanced programmers.

    In the upcoming article, I’ll be explaining how to use X-debug for keeping track of the functions being called during the execution of a PHP script.

    Now that you know the topic for the next tutorial, don’t miss it!



     
     
    >>> 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 5 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek