HomePHP Implementing Destructors with Multiple Objects in PHP 5
Implementing Destructors with Multiple Objects in PHP 5
Welcome to the second installment of the series “Understanding Destructors in PHP 5.” Whether you’re a PHP programmer who’s making their first steps in the area of professional PHP development, or an experienced developer with a solid background in object-based PHP programming, this article series can provide you with an approachable guide for using destructors in PHP 5-controlled development environments.
If you’re starting to get familiar with the numerous features incorporated into the improved object model of PHP 5, then you may have already heard about class destructors. But what are they? Simply put, a destructor is a method defined by a given class that will be automatically called by the PHP interpreter before destroying any instance of that particular class.
Indeed, they can be quite useful for tracking the status of objects during the execution of different scripts. Therefore, if you’re interested in learning how to work with destructors within your own PHP 5 classes, then this group of articles might be what you’re looking for.
Now that I've introduced you to the main subject of this series, I’d like to spend a few moments rehashing the items we discussed in the last article regarding the basic utilization of destructors with PHP 5. As you’ll probably recall, during that particular tutorial I walked you through both the theoretical and practical concepts concerning the definition and implementation of a simple destructor method within a sample class.
In that specific case, I utilized a trivial “User” object to show how its corresponding destructor was called right before destroying the object in question. In this way I illustrated how the functionality of destructors can be exploited using a basic approach.
Naturally, destructors can be used in all sorts of clever ways in the context of a given PHP 5 application, mostly in those cases where it’s necessary to keep track of the status of certain objects prior to their being destroyed by the PHP interpreter. Nevertheless, this is undoubtedly a more complex topic that will be discussed in detail in upcoming articles of the series. So for the moment, I’m going to continue at my own pace, and consequently, in this second chapter you’ll learn how to work simultaneously with multiple classes that concretely implement their respective destructors.
The subject is indeed very interesting, so I think it's time to move forward and keep learning more useful things concerning the usage of destructors with PHP 5. Let’s go!