Singleton with variable parameters

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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(){}
}


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux