You are here: Re: Is this a bug?!!! I cna't believe! Sorry, if im wrong... « PHP « IT news, forums, messages
Re: Is this a bug?!!! I cna't believe! Sorry, if im wrong...

Posted by DvDmanDT on 01/30/05 21:51

Well, unless I'm misstaken, the '=& new' should only be used once with every
class, so your code doesn't really make sense. The reason is that you are
trying to set the A to the new a, not $a to the new a.. Now, A couldn't get
changed I suppose, so therefore, $arr[1] will be a reference to $a, which is
still a reference to A.. Something like that.. I can only guess it'll work
as expected ("(wsx)(wsx)") if you change =&new to =new..

--
// DvDmanDT
MSN: dvdmandthotmail.com
Mail: dvdmandttelia.com
"News.Php.Net" <mark@liw.lt> skrev i meddelandet
news:20050130160659.939.qmail@lists.php.net...
> <?
>
> class A
> {
> var $name;
> function A($str)
> {
> $this->name = $str;
> }
> }
>
> $arr = array();
>
> //Put to array to objects of class A,
> // where their attribute A::a is assigned a different value
> //objects are assigned to an array by reference
>
> $a = &new A("qaz");
> $arr[0] = &$a;
>
> $a = &new A("wsx");
> $arr[1] = &$a;
>
>
> //But watch the output!!!
> // It is "(qaz)(qaz)", which means that the attribute of a first
> // object assigned to array is outputted!!! WHY?!?!!!
> foreach($arr as $a)
> {
> echo "(".$a->name.")";
> }
> ?>

 

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

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