note 83733 added to language.references.arent
| From: | Anonymous at osu1 dot php dot net | Date: | Mon, 09 Jun 2008 18:52:08 +0000 |
| Subject: | note 83733 added to language.references.arent | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-140280@lists.php.net to get a copy of this message | ||
The example given in the text:
<?php
function foo(&$var)
{
$var =& $GLOBALS["baz"];
}
foo($bar);
?>
illustrates (to my mind anyway) why the = and & should be written together as a new kind of
replacement operator and not apart as in C, like $var = &$GLOBALS["baz"];
Using totally new terminology:
To me the result of this function is not surprising because the =& means 'change the
"destination" of $var from wherever it was to the same as the destination of
$GLOBALS["baz"]. Well it 'was' the actual parameter $bar, but now it will be the
global at "baz".
If you simply remove the & in the the replacement, it will place the value of
$GLOBALS["baz'] into the destination of $var, which is $bar (unless $bar was already a
reference, then the value goes into that destination.)
To summarize, =, replaces the 'destination's value; =&, changes the destination.
----
Server IP: 69.147.83.197
Probable Submitter: 76.105.247.92
----
Manual Page -- http://www.php.net/manual/en/language.references.arent.php
Edit -- https://master.php.net/note/edit/83733
Del: integrated -- https://master.php.net/note/delete/83733/integrated
Del: useless -- https://master.php.net/note/delete/83733/useless
Del: bad code -- https://master.php.net/note/delete/83733/bad+code
Del: spam -- https://master.php.net/note/delete/83733/spam
Del: non-english -- https://master.php.net/note/delete/83733/non-english
Del: in docs -- https://master.php.net/note/delete/83733/in+docs
Del: other reasons-- https://master.php.net/note/delete/83733
Reject -- https://master.php.net/note/reject/83733
Search -- https://master.php.net/manage/user-notes.php