I was just wondering something about this.
I wanted to do something similar, like having a mysql class that there can
only be one of. The purpose of this was not to have hundereds to mysql
connections open, and also to track how many queries are being sent/second.
When creating the singleton, I assume you use this syntax:
$var = &new singelton;
However, in the class, how can you check to make sure there has not been
another class created under a different var?
My way of doing it would have been to make a static var in the __construct
class, checking if this has been registered as a var or not. If no, create
class, otherwise exit class.
Would this work? Or is there a better way of doing it?
Thanks.
I wanted to do something similar, like having a mysql class that there can
only be one of. The purpose of this was not to have hundereds to mysql
connections open, and also to track how many queries are being sent/second.
When creating the singleton, I assume you use this syntax:
$var = &new singelton;
However, in the class, how can you check to make sure there has not been
another class created under a different var?
My way of doing it would have been to make a static var in the __construct
class, checking if this has been registered as a var or not. If no, create
class, otherwise exit class.
Would this work? Or is there a better way of doing it?
Thanks.
Comment