HomePHP Using Recursive Methods in Object-based PHP Applications
Using Recursive Methods in Object-based PHP Applications
Welcome to the second tutorial of the series “Recursion in PHP.” Comprised of three parts, this series introduces the fundamentals of recursion in PHP, including the definition and use of recursive functions in procedural PHP scripts, as well as the creation of recursive methods in object-oriented Web applications.
Just in case you don’t remember, in the first article of the series, I explored the basics of recursion, highlighting its benefits and drawbacks, in this way providing an in-depth explanation of how recursive functions work internally. To sustain the underlying theory, I showed numerous hands-on examples, which hopefully demonstrated that defining recursive functions to solve specific programming issues is not only easy, but also instructive and educational.
As I stated in the previous article, sometimes recursion can be used when writing functions and methods aimed at navigating tree structures or linked lists. Also, even when recursion is considered an advanced approach for addressing specific problems (instead of using traditional iteration), it should be utilized with caution. It introduces significant overhead in server memory, and eventually can slow down certain applications.
Now, in this second part of the series, I’ll explore some advanced uses of recursion in PHP, particularly in the terrain of object-oriented programming. I will develop a couple of object-based applications which use recursive methods for accomplishing their tasks. By the end of this tutorial, you should have a pretty solid grounding in how to define recursive methods within your own PHP classes.
With the formalities out of the way, it’s time to leap forward and continue learning more about how to use recursion in PHP. Let’s go!