Posted by gosha bine on 06/02/07 11:50
howa 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();
>
--
gosha bine
extended php parser ~ http://code.google.com/p/pihipi
blok ~ http://www.tagarga.com/blok
[Back to original message]
|