[pLog-svn] PHP - Return by reference?

howard chen howachen at gmail.com
Fri Jan 26 09:15:59 EST 2007


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