Posted by gosha bine on 06/02/07 11:51
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();
>
The second. "foo = new Foo" will create two copies of "Foo" in php4.
Any reason why you can't use php5?
--
gosha bine
extended php parser ~ http://code.google.com/p/pihipi
blok ~ http://www.tagarga.com/blok
Navigation:
[Reply to this message]
|