01-06-2009, 02:01 AM
|
#8 (permalink)
|
|
La Vida es Sueño
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
|
Do you want to use the singleton on an individual basis like the following? Do you really want a factory, as I showed you above?
php Code:
class TalkPHP_Hello { public static $m_pInstance; public static function getInstance () { if (! isset(self:: $m_pInstance)) { self:: $m_pInstance = new self (); } return self:: $m_pInstance; } public function getText() { return 'Hello TalkPHP.com'; }}echo TalkPHP_Hello:: getInstance()-> getText();
This is the best way for it to be application wide. You just call getInstance() and there you have the instance. If you don't need many instances of the object, simply use it like so.
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
|
|
|