PHP
  Home arrow PHP arrow Page 2 - Using the Xdebug Extension`s xdebug_call_function() 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

Using the Xdebug Extension`s xdebug_call_function() Function
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 2
    2009-02-09


    Table of Contents:
  • Using the Xdebug Extension`s xdebug_call_function() Function
  • Review: the xdebug_call_file() and xdebug_call_line() functions
  • Using the xdebug_call_function() function
  • Testing the xdebug_call_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


    Using the Xdebug Extension`s xdebug_call_function() Function - Review: the xdebug_call_file() and xdebug_call_line() functions
    ( Page 2 of 4 )

    As I stated in the beginning, the Xdebug extension includes a couple of useful methods, called "xdebug_call_file()" and "xdebug_call_line()" respectively, which can be utilized conjunctly for determining from which file a function or statement has been called, as well as the line number at which this call was made.

    However, it would be helpful to recall how these functions can be used in two concrete cases. Therefore, below I reintroduced a couple of examples created in the previous article, which demonstrate how to utilize the methods within a sample class. Here they are:

    (example on using the 'xdebug_call_file()' function)


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

    }

    }


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

    }



    (example on using the 'xdebug_call_line()' function)


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

    }

    }


    try{

    $user=new User('Alejandro','Gervasio','alejandro@domain.com');

    echo $user->getLine();

     

    /* displays the following

    Called from line 40

    */

    }

    catch(Exception $e){

    echo $e->getMessage();

    exit();

    }


    Despite the simplicity of the examples listed above, they do demonstrate how to utilize the "xdebug_call_file()" and "xdebug_call_line()" functions to find out from which file a class method has been invoked, and from which program line this call was performed.

    In both cases, for example purposes, these functions were called from inside a sample class, but it's valid to use them when working with procedural functions as well.

    Well, at this stage you hopefully are well prepared for using these two functions in your own PHP applications, if you want to debug them at a basic stage. Therefore, it's time to explore a few other handy functions that come bundled with the Xdebug extension.

    In the following section I will explain how to use the "xdebug_call_function()" function to find out from which function a method or statement has been called when a PHP script is being executed.

    To learn how this brand new function will be utilized in a useful way, please click on the link shown below and keep reading.



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