Before I start teaching you how to use the "var_dump()" function included with the X-debug extension, I will reintroduce the hands-on example created in the preceding article of this series. It demonstrated how to track function calls via the "xdebug_call_function()" method. Put in a simple way, the example in question made use of a sample "User" class, whose signature looked like this: (example on using the 'xdebug_call_function()' 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 the function that was called public function getFunction(){ return 'Called from function '.xdebug_call_function(); } } As you'll probably recall, the above "User" class implemented a basic method called "getFunction()," which utilized the "xdebug_call_function()" function to return to client code the name of the function that originally called the method in question. To help you understand this concept more clearly, below there's a short code sample that demonstrates the functionality of the "xdebug_call_function()" function. Here it is: try{ $user=new User('Alejandro','Gervasio','alejandro@domain.com'); echo $user->getFunction();
/* displays the following Called from function {main} */ } catch(Exception $e){ echo $e->getMessage(); exit(); } Definitely, the previous script is very easy to follow. It shows that the pertinent "getFunction()" method that belongs to the "User" class was called originally from the "main" function in C (remember that PHP was built with this medium-level programming language). Simple and pretty illustrative, right? Now that you've recalled how to use the "xdebug_call_function()" function of the X-debug library to keep track of the different function calls performed during the execution of a PHP script, it's time to explore a few other features provided by this debugging library. In the following section I'll be explaining how to use the enhanced version of the native "var_dump()" PHP function for retrieving useful and abundant information on a specified variable. To see how this function works you'll have to click on the link that appears below and keep reading.
blog comments powered by Disqus |
|
|
|
|
|
|
|