|
Posted by howachen on 05/31/06 17:33
however, php4 support static variable at the function level
which make Singleton implementation possible, sth like that...
e.g.
fucntion getManager() {
static managerInstance;
if (!isset(managerInstance)) {
managerInstance = new Manager();
}
return managerInstance;
};
....
Oli Filth 寫道:
> howachen@gmail.com said the following on 14/05/2006 19:10:
> > Ryan Lange wrote:
> >> howachen@gmail.com wrote:
> >>> if this instance use a lot of memory, would it be better if i use
> >>> reference?
> >>>
> >>> e.g.
> >>>
> >>> //*********************
> >>> public static function &singleton()
> >>> {
> >>> if (!isset(self::$instance)) {
> >>> $c = __CLASS__;
> >>> self::$instance = new $c;
> >>> }
> >>>
> >>> return self::$instance;
> >>> }
> >>> //*********************
> >> By default, objects in PHP5 are passed/returned by reference, so
> >> this is unnecessary.
> >>
> > how about PHP4? need explictly use reference?
> >
>
> Somewhat irrelevant, as PHP 4 doesn't implement static class members.
>
>
> --
> Oli
Navigation:
[Reply to this message]
|