01-07-2009, 02:13 AM
|
#14 (permalink)
|
|
La Vida es Sueño
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
|
That doesn't need to be static as it is called after the getInstance() call. Therefore it is now an object, as it were.
Nonetheless, a very good post!
Another way to do this, although I don't approve of this way, is to use $GLOBALS. I've wrapped it in two functions just to make it look slightly more elegant, but not a lot!
php Code:
class TalkPHP_Hello { public function getText() { return 'Hello TalkPHP.com'; }}class TalkPHP_Hello_Child { public function getText() { /* The above class is now accessible from everywhere! */ return getGlobal ('pHello')-> getText(); }}function getGlobal ($szVariable){ return $GLOBALS[ $szVariable]; }function setGlobal ($szVariable, $pObject){ $GLOBALS[ $szVariable] = $pObject; }setGlobal ('pHello', new TalkPHP_Hello ()); setGlobal ('TalkPHP_Hello_Child', new TalkPHP_Hello_Child ()); echo getGlobal ('TalkPHP_Hello_Child')-> getText();
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
|
|
|