In the previous section, I built a simple decorative class that added a few star characters to an inputted string. The most relevant aspect of this class, however, is obviously that it employs internally the “xdebug_get_function_stack()” function, meaning that it’s necessary to code a short example that demonstrates its functionality. Therefore, below I included a simple code sample. It shows the output generated by this function when called from inside the “NameDecorator” class: $nameDec=new NameDecorator(); $nameDec->displayDecoratedName(array('John','Mary','Susan')); /* displays the following array 0 => array 'function' => string '{main}' (length=6) 'file' => string '/path/to/example/stack_call_example.php' (length=72) 'line' => int 0 'params' => array empty 1 => array 'function' => string 'displayDecoratedName' (length=20) 'class' => string 'NameDecorator' (length=13) 'file' => string '/path/to/example/stack_call_example.php' (length=72) 'line' => int 15 'params' => array empty 2 => array 'function' => string 'displayStars' (length=12) 'class' => string 'NameDecorator' (length=13) 'file' => string '/path/to/example/stack_call_example.php' (length=72) 'line' => int 10 'params' => array empty ********** John array 0 => array 'function' => string '{main}' (length=6) 'file' => string '/path/to/example/stack_call_example.php' (length=72) 'line' => int 0 'params' => array empty 1 => array 'function' => string 'displayDecoratedName' (length=20) 'class' => string 'NameDecorator' (length=13) 'file' => string '/path/to/example/stack_call_example.php' (length=72) 'line' => int 15 'params' => array empty 2 => array 'function' => string 'displayStars' (length=12) 'class' => string 'NameDecorator' (length=13) 'file' => string '/path/to/example/stack_call_example.php' (length=72) 'line' => int 10 'params' => array empty ********** Mary array 0 => array 'function' => string '{main}' (length=6) 'file' => string '/path/to/example/stack_call_example.php' (length=72) 'line' => int 0 'params' => array empty 1 => array 'function' => string 'displayDecoratedName' (length=20) 'class' => string 'NameDecorator' (length=13) 'file' => string '/path/to/example/stack_call_example.php' (length=72) 'line' => int 15 'params' => array empty 2 => array 'function' => string 'displayStars' (length=12) 'class' => string 'NameDecorator' (length=13) 'file' => string '/path/to/example/stack_call_example.php' (length=72) 'line' => int 10 'params' => array empty ********** Susan */ That was pretty interesting, right? As you can see, once the above “NameDecorator” class was fed with an input array comprised of a few trivial names, it echoed to the browser not only their decorated versions, but another array containing relevant information about the script being executed -- including the file name and program lines being parsed, and the stack of functions called by the class. Considering that all of this data was generated by the ““xdebug_get_function_stack()” function, it’s fair to say that it can be really helpful for debugging PHP applications with minor efforts. With this final example I’m finishing this introductory guide to using the Xdebug extension. Since this library includes a lot of other functions, my suggestion is that you read its official documentation for full information on each of them. Happy debugging! Final thoughts It’s hard to believe, but we've finally come to the end of this series. Overall, the experience has been both fun and instructive, since you learned how to install the Xdebug extension and how to use its most relevant functions. As you saw through the code samples created in the articles, the library is pretty intuitive. Best of all, it provides detailed information about common aspects of a PHP program, which can be really helpful for performing debugging tasks that require a great deal of detailed information. See you in the next PHP web development tutorial!
blog comments powered by Disqus |
|
|
|
|
|
|
|