note 72876 added to language.references.arent

From: Date: Sat, 03 Feb 2007 16:31:00 +0000
Subject: note 72876 added to language.references.arent
Groups: php.notes 
Request: Send a blank email to php-notes+get-122679@lists.php.net to get a copy of this message
The manual states: "There's no way to bind $bar in the calling scope to something else using the reference mechanism" This is actually incorrect. It is possible to bind $bar to another object. The given example doesn't work for obvious reasons: $var is redeclared as an alias for $GLOBALS["baz"], instead of an alias for $bar. You should use an ordinary assignment to assign another object to the same variable. This works because variables containing objects actually contain a reference to that object, and the reference is copied to $var, and therefore is copied to $bar as well. When using primitive values, such as integers or strings, the values itself are copied. In the example (when excluding the ampersand from the assignment), suppose that $GLOBALS['baz'] contains the value 3, after calling foo($bar), $bar will contain the integer 3, but they won't point to the same memory space. The correct sentence would be thus: "There's no way make $bar in the calling scope an alias for something else using the reference mechanism" ---- Server IP: 87.238.162.147 Probable Submitter: 134.58.253.130 (proxied: 10.0.8.130) ---- Manual Page -- http://www.php.net/manual/en/language.references.arent.php Edit -- https://master.php.net/note/edit/72876 Del: integrated -- https://master.php.net/note/delete/72876/integrated Del: useless -- https://master.php.net/note/delete/72876/useless Del: bad code -- https://master.php.net/note/delete/72876/bad+code Del: spam -- https://master.php.net/note/delete/72876/spam Del: non-english -- https://master.php.net/note/delete/72876/non-english Del: in docs -- https://master.php.net/note/delete/72876/in+docs Del: other reasons-- https://master.php.net/note/delete/72876 Reject -- https://master.php.net/note/reject/72876 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#122679) next »