Retrieving Information on Several Objects with Destructors in PHP 5 - Displaying data related to different objects using one single destructor
(Page 4 of 4 )
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!
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |