Mailinglisten-Archive |
Hi, Johannes,
> Eher eine statische Variable in der statisch aufgerufenen Funktion. Eine
>
>typishce Singleton implementierung in PHP sieht irgendwie so aus:
>
>function &singleton() {
> static $instance = null;
>
> if ($instance) {
> return $instance;
> }
>
> $instance = &new Objekt();
> return $instance;
>}
>
>$localinstance = objekt::singleton();
>
>
>
Also ich würde behaupten, das geht so nicht. Du setzt die Instanz null
und fragst dann ob es sie gibt? Und erstellst auf _jeden_ Fall ein neues
Objekt? Müsste es nicht ungefähr so aussehen?
class mySingletonClass{
var $instance = null;
function mySingletonClass(){
}
function getInstance(){
if($this->instance==null){
$this->instance = new mySingletonClass();
}
return $this->instance;
}
}
Gruss
Sorin
php::bar PHP Wiki - Listenarchive