Hi guys,

I am trying to generate an abstract Singleton class for use in arbitrary classes, like

class Foo extends Singleton {}

and generate a new class with Foo -> getInstance();

How can I manage to use this with an unkown number of parameters like Foo -> getInstance('a', 'b'); ?

Something like "self::$instance = call_user_func (array(static , "__construct"), func_get_args());" instead of "self::$instance = new self;" doesn't work and an eval() is too slow.

I hope you can help me.

Thanks,
Sebastian

class Singleton
{
static private $instance = null;
static public function getInstance()
{
     if <http://www.phpbar.de/w/if>(null === self::$instance) {
self::$instance = new self;
}
    return <http://www.phpbar.de/w/return>self::$instance;
}
private function __construct(){}
private function __clone(){}
}

Reply via email to