note 76129 deleted from language.references.pass by danbrown
| From: | danbrown@php.net | Date: | Thu, 28 Jan 2010 13:18:37 +0000 |
| Subject: | note 76129 deleted from language.references.pass by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-165414@lists.php.net to get a copy of this message | ||
Note Submitter: riseofthethorax at gmail dot com
----
Okay got it.. Why can't you guys just weed this out in the preprocessor? It's nothing more
than a syntactical difference..
function foo(&$a) {
$a = ($a++) * 6;
}
$x = 10;
foo($x);
print $x ; // 66
versus
foo(&$x);
which probably gets interpretted as pass a reference to x,
then once in foo, a reference is made to a reference of x..
I suppose this would be a memory leak because $a is
now a reference to $x that was declared when calling the function, is not being used by anyone..
I suppose it is like this..
we call foo(&$x);
A reference (I'll call it $*) is created that links to $x.
Inside foo, $a is assigned a reference to $*, which is $x.
$x is modified with $a is modified..
Coming out of foo.. $a is destroyed..
reference $* still exists because it was created outside of foo..
But there is no way of referring to it because it has no name..
Is this the reason, is this why call-time pass-by-reference was deprecated??
I don't see why it was just weeded out by the preprocessor.. Nobody would make use of this
artifact..
However, I need pass by reference, there is no way I can get stuff done without it..