one object

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I want to build one object that will be reuse all the time, so I just
need to create it once for all, how can I do that. A sort of static object.

Re: one object

David Nguyen wrote:
Quoted text here. Click to load it

Depending on how you want to use it (application or page wide) you could
settle for a session reference to the object or a singleton class (or a
combination of both).

When you do not know what a singleton is, here are some examples:

PHP 4:

PHP 5:

class Singleton {
     private static $_instance = null;

     public static function getInstance () {
          if (self::$_instance == null) {
              self::$_instance = new self;
          return self::$_instance;

$singleton = Singleton::getInstance();


Site Timeline