PHP
  Home arrow PHP arrow Page 3 - 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 - Keeping track of file calls with the X-debug extension
    ( Page 3 of 4 )

    One of the most basic features that any decent PHP debugging library must have is the ability to keep track of which files are used by a script or application, including files that are loaded via “include” directives.

    Fortunately, the X-debug extension provides this information in an easy-to-read format via its “xdebug_call_file().” As its name suggests, it returns the file name of the file being called for a PHP script.

    Although the functionality of this function is pretty simple to grasp, the best way to understand how it works is by setting up a concrete example. With this idea in mind, I’m going to define a simple class, which will implement one of its methods with the aforementioned “xdebug_call_file()” function.

    Here is how this sample class looks:


    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;

    }

    // get file from which this method was called

    public function getFile(){

    return 'Called from file '.xdebug_call_file();

    }

    }


    Certainly, I’m not going to waste your time explaining how the above “User” class works, since this would be pretty pointless. You should, however, pay attention to the implementation of its “getFile()” method. This method internally uses the “xdebug_call_file()” function of the X-debug extension to return to client code the name of the file being called by the current script.

    This shouldn’t be difficult to grasp, but to dissipate any possible doubts, please take a look at the following code sample. It shows the output generated by the “xdebug_call_file()” function. Here it is:


    try{

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

    echo $user->getFile();

     

    /* displays the following

    Called from file C:pathtofiledebug_call_file_example.php

    */

     

    }

    catch(Exception $e){

    echo $e->getMessage();

    exit();

    }


    As shown above, the “xdebug_call_file()” function returns the name of the file from which the “getFile()” method was called, which makes it really easy to keep track of the different files that are used by a PHP script. In this case, I decided to keep the previous example as simple as possible, to help you understand more easily how this function works in a concrete situation.

    At this point, I’m sure that you grasped how to utilize the prior “xdebug_call_file()” function to determine from which file a function, method or statement has been called when running a PHP script. Nonetheless, the X-debug extension offers another function, called “xdebug_call_line(),” which can be used for determining from which line an instruction has been invoked.

    In the upcoming segment, I’m going to illustrate how to use this brand new debugging function. Please click the link that appears below and read the next few lines.



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