Posted by carrion on 06/04/07 14:32
On Jun 2, 11:23 am, howa <howac...@gmail.com> wrote:
> 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();
I didn't really read the follow-ups, but you should take care of the
typos first. This ain't no singleton. $instace != $instance
Navigation:
[Reply to this message]
|