You are here: Re: Need to return reference in this case? « PHP Programming Language « IT news, forums, messages
Re: Need to return reference in this case?

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация