David Nguyen wrote:
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. Thanks
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:
http://www.jwscripts.com/playground/singleton.phps
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();
JW