Re: Argument passed by reference?

From: Date: Tue, 11 Apr 2006 01:42:50 +0000
Subject: Re: Argument passed by reference?
References: 1 2 3 4 5  Groups: php.general 
Request: Send a blank email to php-general+get-233717@lists.php.net to get a copy of this message
It's not that it's not allowed, it's that it should be done differently. You should make the function accept a reference in the definition, not pass in a reference to the function. The manual page has a good, simple example on what to do. http://www.php.net/manual/en/language.references.pass.php
Chris: Interesting. One would think (at least I do) it should be the other way around. Using the example given at the link above: <?php function foo(&$var) { $var++; } $a=5; foo($a); // $a is 6 here ?> We have one function that works one way. <?php function foo($var) { $var++; } $a=5; foo(&$a); // $a is 6 here ?> However, doing it this way, the function can serve two purposes. I can send it a reference or I could send it a value. I know that in this function a value doesn't do anything, but it could if the function was different. Plus, in the first function, I can't send it a reference (i.e., a reference to a reference?). What's short reasoning for this being recommended this way? What am I not seeing? tedd -- -------------------------------------------------------------------------------- http://sperling.com

« previous php.general (#233717) next »