Before I start explaining how to use the aforementioned “xdebug_start_code_coverage()” and “xdebug_get_code_coverage()” functions, I will quickly review the practical example created in the preceding article of this series. It demonstrated how to retrieve relevant information about a specified object through the “var_dump()” function. Basically, the entire source code of the example in question looked like this: (example on using the 'var_dump()' function with a sample array) 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; } } try{ $user=new User('John','Doe','john@domain.com'); $data=array('string'=>'This is a string','integer'=>1,'float'=>0.123456,'object'=>$user); var_dump($data);
/* displays the following array 'string' => string 'This is a string' (length=16) 'integer' => int 1 'float' => float 0.123456 'object' => object(User)[1] private 'firstName' => string 'John' (length=4) private 'lastName' => string 'Doe' (length=3) private 'email' => string 'john@domain.com' (length=15) */ } catch(Exception $e){ echo $e->getMessage(); exit(); } As shown above, the “var_dump()” function can be very helpful for retrieving information about a group of specified variables, since its functionality has been extended when used with the Xdebug library. In this specific case, the function has been fed with a basic array of elements, where one of them is an instance of the “User” class listed before. Aside from retrieving the name of the object passed as an incoming argument, the function also returns a few other helpful values. These include the name of its properties and the corresponding length expressed in characters. At this stage, and having already reviewed how the “var_dump()” function does its thing, it’s time to explore more functions that come bundled with the Xdebug extension. Thus, as I explained in the introduction, the library allows you to follow the flow of a specified application by means of the “xdebug_start_code_coverage()” and “xdebug_get_code_coverage()” functions. Thus, in the upcoming section I’ll be coding a brand new example. It will demonstrate how to use these functions to determine which lines are executed by a PHP program. Click on the link below and keep reading, please.
blog comments powered by Disqus |
|
|
|
|
|
|
|