Home arrow PHP arrow Using Different Target Files for Persistent Objects

Using Different Target Files for Persistent Objects

Persistent objects appear at first to be an obscure and hard-to-grasp subject that belongs under software development. In fact, persistent objects are simply regular objects spawned from a class that has some form of storage mechanism associated with it. This six-part series shows you how to get the most out of persistent objects in your web applications.

  1. Using Different Target Files for Persistent Objects
  2. Review: saving object properties to a predetermined text file
  3. Saving class properties to different text files
  4. Restoring the persistent object on a different web page
By: Alejandro Gervasio
Rating: starstarstarstarstar / 2
September 28, 2009

print this article



In the particular case of PHP 5, which as you know is well-suited for building web applications, persistent objects are very often created to overcome the stateless nature of the HTTP protocol. This implies defining classes that are capable of saving the state of their instances to a database table, a text file or a plain cookie. (Keep in mind, though, that this last option is considered to be a pretty unsafe solution because it relies heavily on the client’s environment to work properly).

Naturally, if you’ve been a patient reader and had the chance to read all of the previous articles in this series, then by now building persistent objects in PHP 5 should be familiar to you. In those articles I've used a decent number of code samples to help explain how to create these objects. My first examples showed how to do it with a few cookies; later, I demonstrated the technique using a predefined text file.

More specifically speaking, in the last article I defined a simple class that could save the properties assigned to its instances to a unique file called “data.txt.” While this example class could be considered a genuine persistent entity, I have to admit that in its current state, it lacks some flexibility. After all, it can only store its properties in a single text file, which is not too useful. 

To address this limitation, in this fourth part of the series I’m going to tweak the definition of the class created in the previous article. The modification will allow it to save its properties to different text files, thus considerably enhancing its functionality. 

Are you ready to learn more about building persistent objects with PHP 5? Then  start reading now!

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

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


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