[pLog-svn] PHP - Return by reference?

Jon Daley plogworld at jon.limedaley.com
Tue Jan 30 09:47:08 EST 2007


 	Do you gain anything by your method?  Or is it just a coding 
practice difference?

On Tue, 30 Jan 2007, howard chen wrote:

> 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;
>>
> _______________________________________________
> pLog-svn mailing list
> pLog-svn at devel.lifetype.net
> http://limedaley.com/mailman/listinfo/plog-svn
>

-- 
Jon Daley
http://jon.limedaley.com/

The shortest distance between two points is under construction.
-- Altito


More information about the pLog-svn mailing list