Home arrow PHP arrow Page 3 - Using the Xdebug Extension`s xdebug_call_function() Function

Using the xdebug_call_function() function - PHP

Among the numerous PHP debugging libraries available these days on the web, there’s one that offers easy installation and a flat learning curve, along with powerful features that permit you to debug PHP applications with minor hassles. I'm talking about the Xdebug extension, of course, and in this second part of a seven-part series you'll learn how to use its xdebug_call_function () function.

  1. Using the Xdebug Extension`s xdebug_call_function() Function
  2. Review: the xdebug_call_file() and xdebug_call_line() functions
  3. Using the xdebug_call_function() function
  4. Testing the xdebug_call_function()
By: Alejandro Gervasio
Rating: starstarstarstarstar / 2
February 09, 2009

print this article



Quite often when debugging a PHP application, it's necessary to find out from which function a method or statement has been called. To accomplish this task with minor efforts, the Xdebug extension provides the "xdebug_call_function()" function (the name isn't redundant, trust me).

As usual, to demonstrate how this function can be used in a concrete situation, I'm going to appeal to the functionality of the "User" sample class that was built in the first article. However, in this case, this class will implement a new method, called "getFunction()," which will show you how to work with the "xdebug_call_function()" function.

Here's the modified signature of this class, so pay attention to the way it functions:

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 the function that was called

public function getFunction(){

return 'Called from function '.xdebug_call_function();



As you can see, the above "User" class now declares and implements a new method called "getFunction()" that internally uses the "xdebug_call_function()" to return to client code the name of the function that invoked the method.

As with the other functions discussed in the preceding article, this one can also be used when debugging procedural PHP programs, so it's clear to see that there's plenty of room for experimenting with this brand new function.

Now, and returning to the implementation of the above "getFunction()" method, it should be extremely easy to grasp for you, even though it still hasn't been used in the context of a practical example. Don't worry; in the following section I will write a short code sample that will help to demonstrate the actual functionality of the "xdebug_call_function()."

To learn how this new example will be developed, please click on the link 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: