PHP
  Home arrow PHP arrow Building Persistent Objects in PHP 5
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
Google.com  
PHP

Building Persistent Objects in PHP 5
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 6
    2009-09-15


    Table of Contents:
  • Building Persistent Objects in PHP 5
  • Introducing persistent objects in PHP 5
  • Implementing a destructor method
  • Putting the sample User class into action

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Building Persistent Objects in PHP 5
    ( Page 1 of 4 )

    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.

    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
     

       

    PHP ARTICLES

    - Adding Ordering and Grouping Clauses to the ...
    - Implementing Factory Methods in PHP 5
    - Merging a File Split for FTP Upload using PHP
    - Getting Data from Yahoo Site Explorer Inboun...
    - Method Chaining: Adding More Selecting Metho...
    - How to Split a File During an FTP Upload Usi...
    - Expanding a Custom CodeIgniter Library with ...
    - Using the Yahoo Site Explorer Inbound Links ...
    - Building a CodeIgniter Custom Library with M...
    - Building an E-mini Trading System Using PHP ...
    - Completing the MySQL Class with Method Chain...
    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek