Re: Singleton Pattern?

From: Date: Thu, 18 Mar 2004 22:56:33 +0000
Subject: Re: Singleton Pattern?
References: 1  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-26571@lists.php.net to get a copy of this message
On 18 Mar 2004 at 16:30, Paul M Jones wrote: > Hi everyone, > > This is not strictly PEAR-related, but it is for a PEAR class I'm > developing. If this is not the place, I'll ask elsewhere. > > I am trying to implement a singleton pattern, but I am having the > darnedest time. Have examined various examples (e.g., phppatterns.com, > PEAR Log), but my own simple tests are failing. [...] > > In theory, the output should be "create something reuse something" > (i.e, $one gets a newly created test object, sets the value, and gets > the value; $two should get a reference to the static test object and > get the value from that same object). > > However, the actual output is "create something reuse default" (i.e., > $two is getting a new object, not the re-used reference to the static > singleton). > > Is there something obvious that I am doing wrong? I don't know "what" you are doing wrong and "why" it fails. But I know how to solve it: simply omit the ampersand before new test(); Maybe there is a problem when $obj is a reference and you try to make that static? I've had similar problems with the new-operator (sometimes with, sometimes without ampersand) - but in this case seems to work. However, I'd really appreciate somebody with more knowledge about this "problem" to enlighten us a bit. Paul, hope that helps you out for the moment. Tried, works! Regards, Stefan

« previous php.pear.dev (#26571) next »