Re: Argument passed by reference?
| From: | tedd | Date: | Fri, 07 Apr 2006 23:06:19 +0000 |
| Subject: | Re: Argument passed by reference? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-233493@lists.php.net to get a copy of this message | ||
At 1:24 PM -0500 4/6/06, Chris Boget wrote:
Is there a way to test to see if a function argument was passed by reference instead of by value? thnx, ChrisChris: As I am sure you know, passing by reference is simply passing the memory address of the variable to a function instead of it's value. If the receiving function does something to the variable at that address, then the value at that address is changed. You can test this by simply checking the value before and after it's returned from the function. For example, the following just passes the memory address of variable $a to a function. After which, the function alters the variable at that memory address, but doe not return a value. But, echoing the variable after the function call shows that the variable has indeed been altered. <?php $a = 10; echo("$a <br/>"); ref(&$a); echo("$a"); ?> <?php function ref($a) { $a--; } ?> HTH's tedd -- -------------------------------------------------------------------------------- http://sperling.com