Home arrow PHP arrow Page 4 - Retrieving Information on Several Objects with Destructors in PHP 5

Displaying data related to different objects using one single destructor - PHP

Welcome to the fourth part of the series “Understanding Destructors in PHP 5.” Made up of five comprehensive tutorials, this series brings to you the foundations of how to declare and implement destructors in PHP 5-driven classes. And it tackles this process from a practical point of view, since you’ll be able to learn these methods by using copious examples.

TABLE OF CONTENTS:
  1. Retrieving Information on Several Objects with Destructors in PHP 5
  2. Keeping track of a single object
  3. Working with different user handling objects
  4. Displaying data related to different objects using one single destructor
By: Alejandro Gervasio
Rating: starstarstarstarstar / 5
February 06, 2008

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

As I promised you in the section that you just read, here’s the output generated by the script developed before. As you’ll see in a moment, it displays not only the first and last names and email addresses of those fictional users, but prints their respective methods and properties as the destructor is being called by the PHP interpreter.

Having explained that, please take a look at the following screen results:


First Name: John

Last Name: Doe

Email: john@domain.com

Complete user information: First Name: John Last Name: Doe Email Address: john@domain.com


First Name: Mary

Last Name: Smith

Email: mary@domain.com

Complete user information: First Name: Mary Last Name: Smith Email Address: mary@domain.com


First Name: Susan

Last Name: Norton

Email: susan@domain.com

Complete user information: First Name: Susan Last Name: Norton Email Address: susan@domain.com

 

Properties of object being destroyed

firstName=John

lastName=Doe

email=john@domain.com

 

Methods of object being destroyed

Method Name: __construct()

Method Name: getFirstName()

Method Name: getLastName()

Method Name: getEmail()

Method Name: getAll()

Method Name: __destruct()

 

Properties of object being destroyed

firstName=Mary

lastName=Smith

email=mary@domain.com

 

Methods of object being destroyed

Method Name: __construct()

Method Name: getFirstName()

Method Name: getLastName()

Method Name: getEmail()

Method Name: getAll()

Method Name: __destruct()

 

Properties of object being destroyed

firstName=Susan

lastName=Norton

email=susan@domain.com

 

Methods of object being destroyed

Method Name: __construct()

Method Name: getFirstName()

Method Name: getLastName()

Method Name: getEmail()

Method Name: getAll()

Method Name: __destruct()


As illustrated above, by using only one simple destructor, it’s perfectly possible to display data related to the structure of some trivial user handling objects prior to the corresponding deletion by the PHP engine. Short and effective!

So far, so good. At this point, you hopefully have a more solid background on using destructors with PHP 5 to collect data concerning the structure of certain objects. In addition, you’re free to use all of the code samples built here, with the purpose of expanding your skills in utilizing these useful methods.

Final thoughts

In this fourth part of the series, you learned, with the help of a few easy-to-follow examples, how to exploit the functionality provided by destructors to retrieve information about a bunch of objects before they were removed from memory.

But in this case, it’s fair to mention that all of the examples shown so far have used destructors that are called automatically by the PHP engine. Therefore, in the final article of the series I’ll teach you how to manually trigger a destructor method before giving this chance to the interpreter.

Intrigued about how this will be done? Don’t miss the last chapter of this journey!



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

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- 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: