Home arrow PHP arrow 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.

  1. Implementing Destructors with Multiple Objects in PHP 5
  2. Handling user-related data with a simple PHP 5 class
  3. Working with multiple objects by redefining the destructor of the previous “User” class
  4. Finding out the order in which several destructors are called by the PHP interpreter
By: Alejandro Gervasio
Rating: starstarstarstarstar / 6
January 23, 2008

print this article



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!

>>> More PHP Articles          >>> More By Alejandro Gervasio

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates


Dev Shed Tutorial Topics: