If you’re a PHP developer who wants to learn how to create objects that can maintain their state through different HTTP requests, either by using cookies, plain text files or MySQL database tables, then don’t look any further because you’ve come to the right place. Welcome to the last part of a six-part series on building persistent objects in PHP 5. This tutorial series introduces the key concepts that surround the creation of persistent objects, and complements the corresponding theory with copious code samples.
And now that you know what to expect from this set of articles, it's time to review the topics that were discussed in the last one. In that part of the series I built a simple example class in PHP 5, which was able to save its properties, along with the values assigned to them, to a MySQL table.
All of the database operations required to save the example class's properties were delegated to an instance of a basic MySQL abstraction class. This abstraction class was injected (or aggregated) into the constructor of the persistent class.
Of course, the best part of defining a class like this is that it's possible to retrieve its properties at a later time on a different PHP file, thus building a software entity that can persist (at least partially) across a number of web pages.
However, the best way to understand how the two classes referenced above can interact with each other is by means of a concrete example. Therefore, in this last installment of the series I'm going to set up that example for you. Doing so will wrap up this introductory guide to building persistent objects in PHP 5.
Ready to tackle the final chapter of this hopefully instructive journey? Then, let's get started right now!