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

Posted by Jerry Stuckle on 09/27/10 11:37

Chung Leong wrote:
>
> In a way the term "reference" is unfortunate. In C++ being a reference
> is a variable's intrinsic, whereas in PHP a variable "is a reference"
> if the data it points to is shared--an external condition.
>

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.

The big difference is - $i has independent storage assigned to it to
contain the data. $j does not contain any data - it only "refers" to $i.

> One could argue that there is no changes on the right-hand-side of an
> assignment if = and & are treated as separate operators and any
> side-effect is caused by the latter. You can put white spaces between
> the two after all. On the other hand, & is really just a modifier and
> we have just one operator even with white spaces. In any event, a
> couple changes can occur on the right-hand-side of a =&:
>

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

> 1. $b =& $a makes both $b and $a references. This is actually perfectly
> logical: since $a and $b are point to the same data, $a can be used to
> modify what's in $b--hence it is a reference. It's only funky from the
> C/C++ perspective, as the type of $a has suddenly changed.
>

Nope, the type of $a has NOT changed.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

 

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

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