Reply to Re: [PHP] Is this a bug?!!! I cna't believe! Sorry, if im wrong...

Your name:

Reply:


Posted by Marek Kilimajer on 01/30/05 18:25

No

news.php.net wrote:
> <?
>
> 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;

$arr[0] and $a reference now the same variable

>
> $a = &new A("wsx");

by changing $a you also changed $arr[0]

> $arr[1] = &$a;

now $a, $arr[0] and $arr[1] reference the same variable, they just have
different names.

More:
http://sk.php.net/manual/en/language.variables.php
http://sk.php.net/manual/en/language.references.php

>
>
> //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.")";
> }
> ?>
>

[Back to original 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

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