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!
blog comments powered by Disqus |
|
|
|
|
|
|
|