Re: quickform_controller: sing-sing-singleton
| From: | Justin Hendrickson | Date: | Tue, 13 Jan 2004 23:14:34 +0000 |
| Subject: | Re: quickform_controller: sing-sing-singleton | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-10152@lists.php.net to get a copy of this message | ||
You can create a singleton function to do this for you, using a static variable, which would look something like this:
function & mySingleton
{
static $obj;
if ( empty ( $obj ) )
{
// Load a library
require 'object.php';
// Create the object
$obj = new Object ();
}
return $obj;
}
Many of the PEAR classes out there use similar approaches and I've had success using these kind of functions for classes that don't have their own singleton methods.