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