Home arrow PHP arrow Page 3 - The X-debug Extension

Keeping track of file calls with the X-debug extension - PHP

If you program at all, you understand the necessity of debugging. Fortunately, depending on the language in which you program, you can find an assortment of tools to help you with this task. One very good debugging tool for PHP is the X-debug extension. This seven-part series will reveal its capabilities and help you add it to your programmer's toolbox.

  1. The X-debug Extension
  2. Getting started using the X-debug library
  3. Keeping track of file calls with the X-debug extension
  4. Working with the xdebug_call_line() function
By: Alejandro Gervasio
Rating: starstarstarstarstar / 3
February 02, 2009

print this article



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


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;


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


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



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

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: