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 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]


Удаленная работа для программистов  •  Как заработать на 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

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