note 69027 added to language.references.arent

From: Date: Sun, 20 Aug 2006 12:59:39 +0000
Subject: note 69027 added to language.references.arent
Groups: php.notes 
Request: Send a blank email to php-notes+get-116086@lists.php.net to get a copy of this message
You can think of references as pointers, if you translate a=b into "*a = *b" and a =& b into "a=b". Let's translate to C: <?PHP const int c_1 = 1, c_2 = 2; int * a = &c_1; int * b = &c_2; void foo (int * var) { var = a; } ?> Here, it's obvious that calling foo(b) won't change the value of a, because var is a copy of b. You also have to be careful: order does matter. I could draw a diagram, but I won't. <?php $b=1; $d=2; $a =& $b; $c =& $d; // now a=b=1; c=d=2; $b =& $c; // now a=1, b=c=d=2; ?> It's also important to treat =& as its own operator, though you can stick spaces in the middle. The & does not bind to the variable, as shown by <?php $a = (&$b); // parse error ?> ---- Server IP: 66.163.161.117 Probable Submitter: 82.71.54.164 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/language.references.arent.php Edit -- https://master.php.net/note/edit/69027 Del: integrated -- https://master.php.net/note/delete/69027/integrated Del: useless -- https://master.php.net/note/delete/69027/useless Del: bad code -- https://master.php.net/note/delete/69027/bad+code Del: spam -- https://master.php.net/note/delete/69027/spam Del: non-english -- https://master.php.net/note/delete/69027/non-english Del: in docs -- https://master.php.net/note/delete/69027/in+docs Del: other reasons-- https://master.php.net/note/delete/69027 Reject -- https://master.php.net/note/reject/69027 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#116086) next »