You are here: Re: PHP brain teaser « PHP Programming Language « IT news, forums, messages
Re: PHP brain teaser

Posted by Chung Leong on 09/28/34 11:37

Jerry Stuckle wrote:
> Actually, not. In C++ a reference is a different type of variable.
>
> int i = 4; // the real thing
> int & j = i; // a reference to i.
>
> The second statement does NOT change i in any way. the same is true in PHP:
>
> $i = 4;
> $j = & $i;
>
> $i is an value; $j is a reference to the value.

That's a common misconception about references in PHP. I suggest
reading the article that Tim referred to earlier.

> No, there is no change in $i when you assign a reference to it.

I am afraid you're arguing with reality here. To illustrate...

<?php

$obj->i = 5;
debug_zval_dump($obj);

$obj->j =& $obj->i;
debug_zval_dump($obj);

?>

Result:

object(stdClass)(1) refcount(2){
["i"]=>
long(5) refcount(1)
}
object(stdClass)(2) refcount(2){
["i"]=>
&long(5) refcount(2)
["j"]=>
&long(5) refcount(2)
}

 

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

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