Home arrow PHP arrow Saving Class Instances to Files with Persistent Objects

Saving Class Instances to Files with Persistent Objects

Welcome to the third part of a six-part series on building persistent objects in PHP 5. Through a decent variety of code samples, this series provides you with the right pointers to start creating objects that can save themselves to a persistent storage mechanism, including simple cookies, plain text files, and MySQL database tables.

TABLE OF CONTENTS:
  1. Saving Class Instances to Files with Persistent Objects
  2. Review: a basic persistent class
  3. Saving class instances to a text file
  4. Retrieving an object in a different PHP file
By: Alejandro Gervasio
Rating: starstarstarstarstar / 3
September 22, 2009

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

Though it may sound scary and a bit intimidating, creating objects in PHP 5 that can maintain their state through a number of HTTP requests is an extremely simple process. It only requires an intermediate background in the object-oriented paradigm, along with a basic understanding of how to serialize/unserialize objects.

So, if you’re a PHP developer who wants to master the key concepts that surround the creation of this kind of object without having to spend endless hours reading the PHP manual, then this group of articles may be the material that you’re looking for.

And now that you've been introduced to the main goal of the series, it’s time to review the topics that were covered in the last article. In that tutorial I explained  how to build a basic PHP 5 class which was capable of saving an instance of itself to a specified session variable. This ability allowed it to persist across different web pages.

Also, it’s worth mentioning that this class implemented a static factory method, which allowed it to retrieve class instances in a truly painless way, without our having to explicitly code any constructor.

Though, as I said a few moments ago, a persistent object can also use different mechanisms to maintain its status; that naturally includes text files. Thus, in this third chapter of the series, I’m going to discuss how to build a class that stores instances of itself in a specified file.

Are you ready to learn more on this topic? Start reading right now!



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

blog comments powered by Disqus
   

PHP ARTICLES

- 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...
- PHP: Building Concrete Validators
- Sanitizing Input with PHP
- Executing Shell Commands with PHP
- Handling File Data with PHP
- File Security and Resources with PHP
- ArrayObject PHP Class Examples
- ArrayObject PHP Class: An Introduction
- Getting File System Data with PHP
- PHP Tools for Working with the File and Oper...
- Working with the File and Operating System w...
- PHP Proxy Patterns: Completing a Blog


© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 3 - Follow our Sitemap

Dev Shed Tutorial Topics: