[pLog-svn] PHP - Return by reference?

howard chen howachen at gmail.com
Tue Jan 30 08:46:58 EST 2007


any updates?

thanks.


On 1/26/07, howard chen <howachen at gmail.com> wrote:
> On 1/26/07, Oscar Renalias <oscar at renalias.net> wrote:
> > We're not using those return-by-reference because of performance
> > reasons but because of design reasons.
> >
> > We are just applying the Singleton pattern to make sure that there is
> > only one instance of the class used in the code. We want to make sure
> > that there is only one Config class, one Db class or one
> > PluginManager class instead of having multiple instances of them
> >
>
> if you are using static variable inside the function, there is no need
> to use & ?
>
> e.g.
>
>
> class Singleton {
>
>         var $state;
>
>         function getInstance() {
>                 static $instance;
>
>                 if ( !isset($instance) ) {
>                         $instance = new Singleton();
>                 }
>                 return $instance;
>         }
> }
>
>
>
>
> $i = Singleton::getInstance();
> $i->state = 100;
> print $i->state;
>
> $j = Singleton::getInstance();
> print $j->state;
>


More information about the pLog-svn mailing list