| 
 Posted by howa on 06/02/07 09:23 
a simple singleton class (PHP4) 
 
which way is preffered? 
 
// 1. 
class Foo { 
 
	function getFoo() { 
		static $instace; 
		if (!isset($instace) ) { 
			$instance = new Foo(); 
			// ... 
		} 
		return $instance; 
	} 
} 
 
$foo = Foo::getFoo(); 
 
// 2. 
 
class Foo { 
 
	function &getFoo() { 
		static $instace; 
		if (!isset($instace) ) { 
			$instance = new Foo(); 
			// ... 
		} 
		return $instance; 
	} 
} 
 
$foo =& Foo::getFoo();
 
  
Navigation:
[Reply to this message] 
 |