HomePHP Keeping Track of Objects when Using Destructors in PHP 5
Keeping Track of Objects when Using Destructors in PHP 5
Among the improvements that were introduced into the object model of PHP 5, class destructors are quite possibly, one of the easiest to learn and implement. As you may have heard, a destructor is a special kind of method that is called automatically by the PHP interpreter right before destroying a particular object. So if you’re interested in learning how to use them in your own PHP 5-driven applications, you should start reading this article series!
This is the third chapter of the series "Understanding destructors in PHP 5." In the different tutorials that comprise the series, you'll find the right pointers to start utilizing destructors within your PHP 5 classes. And in addition to learning the corresponding theory regarding these useful methods, you'll be provided with copious hands-on examples aimed at demonstrating, in a practical way, how to get the most out of them.
Now that you're well aware of the main subject of this series, I'm going to take a few minutes of your valuable time to rehash the topics that were discussed in the last article. As you'll probably recall, during the course of that article, I went through the definition of a highly generic user handling class, which when implemented at a basic level, is a primitive destructor method.
The purpose was simply to demonstrate the order in which multiple destructors were called by the PHP interpreter, when using some of the user handling objects that I mentioned earlier. The final result of this testing process was pretty obvious: the PHP engine used the same order in which these objects were constructed, to destroy them; something that was clearly shown by the respective destructors.
Even though this particular example doesn't have a direct application in real world conditions, it should help you understand the priority scale used by the PHP parser when it comes to calling multiple destructors during the execution of a given application.
So far, so good. Now that you hopefully remember all the details concerning the use of several destructors in PHP 5, it's time to continue learning more about these helpful methods. Therefore, in this third part of the series, I'm going to show you how to retrieve some useful information about a specific object, including its properties and methods, prior to its being destroyed by the PHP parser via the implementation of a simple destructor.
Want to see how this will be achieved? Jump into the next few lines and begin reading now!