To show you the use of the “xdebug_get_function_stack()” function as clearly as possible, I’m going to build another sample class. It will be tasked with performing a pretty trivial task -- decorating any string passed in as an incoming argument with a few stars. Regardless of the simplicity of the logic implemented by this class, it should illustrate how to use the “xdebug_get_function_stack()” function in a specific case. Here’s the signature corresponding to this sample class, which I dubbed “NameDecorator”: class NameDecorator{ public function displayStars(){ var_dump(xdebug_get_function_stack()); return str_repeat('*',10); } public function displayDecoratedName($names=array()){ foreach($names as $name){ echo $this->displayStars().' '.$name.'<br />'; } } } Definitely, the signature of the above “NameDecorator” class is pretty easy to follow, isn’t it? As shown before, this class declares and implements only two basic methods. The first one is charged with generating a string composed of ten star characters, which will be added to each name passed in as an input parameter. This “decorative” process will be performed by the second “displayDecoratedName()” method, which you should grasp in a snap. However, the most important thing to note here is that the class will make use of the “xdebug_get_function_stack()” function to display the content of the stack of function calls. Now that there’s a sample class available for illustrating how the “xdebug_get_function_stack()” function does its thing, it’s time to create a final example to show you how this function can keep track of the stack of methods called by the “NameDecorator” class. Wait are you waiting for? Click on the link below and read the following section.
blog comments powered by Disqus |
|
|
|
|
|
|
|