Home arrow PHP arrow Building Persistent Objects in PHP 5

Building Persistent Objects in PHP 5

The HTTP protocol is stateless, but sometimes it is necessary to make web applications store or remember information. This is sometimes referred to as persistent storage, and it takes on a number of different forms. This six-part series of articles will explain the concept and show you various ways to give your web applications a memory.

TABLE OF CONTENTS:
  1. Building Persistent Objects in PHP 5
  2. Introducing persistent objects in PHP 5
  3. Implementing a destructor method
  4. Putting the sample User class into action
By: Alejandro Gervasio
Rating: starstarstarstarstar / 8
September 15, 2009

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

Very often, youíll hear web developers to say (sometimes with a subtle sense of arrogance) that a certain application uses a persistent storage mechanism to save the data it needs to work properly. This is nothing but an elegant way to say that a web program uses a relational database, a simple text file or even a single cookie, to store pieces of data across different HTTP requests.

The stateless nature of the HTTP protocol frequently requires working with these storage mechanisms, even in their simplest form. Moreover, if youíve developed a few web-based programs that interact with MS SQL, MySQL, or an Oracle database, then youíve already created persistent data layers, whether or not you realized it.

Unquestionably, when using PHP 5 the most common type of persistent storage system associated with the language is one or multiple MySQL databases, but as I said before, cookies and plan text files also fall under this category. Typically, though a persistent storage mechanism will store chunks of data that donít have an explicit meaning when analyzed separately, such as strings or numbers, itís also possible to save entire objects, or a particular state of those objects.

This possibility brings to the table the concept of persistent objects, or objects that are capable of maintaining themselves or their state across several HTTP requests. The best part is that these objects are much simpler to create than you might think; the creation process requires only an intermediate background in using the object-oriented paradigm with PHP 5, as well as a basic idea of how to serialize and unserialize objects. Thatís all youíll need, really.

So, in this set of articles, Iím going to explain, with code samples, how to build persistent objects in PHP 5. First we'll use simple cookies to ďpersist,Ē and once you've properly digested the the key concepts, Iíll utilize text files, and finally, a single MySQL database table.

Finally, Iíd like to say that some of the classes that Iím going to build in the subsequent tutorials of this series will be inspired partially by the example class developed by Martin Jansen in its excellent article on Object Overloading in PHP 5. Kudos to him for that.

Having clarified that point, letís leave the boring theory behind and start learning the basics on creating persistent objects. Letís begin right away!



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