Date: 12/29/00
- Next message: Mukul Sabharwal: "Re: [PHP] How setcookie and header can be used together?"
- Previous message: Chad Day: "[PHP] Help with sessions and netscape."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
"Toby Butzon" <php-lists <email protected>> writes:
> What you're trying to do _can_ be done using PHP's references.
>
> When PHP parses your code, it builds a array/hash which holds variables by
> name and value (among other things which are insignificant to this
> discussion, such as type, size, etc.). If you create a reference, PHP just
> adds an additional key for the same value (hence the variable's contents are
> not copied, and an alias is created).
>
> If you are creating large variables within functions and want to keep from
> copying the value to a new variable, _do_ return it as a reference AND
> assign the function's return to the variable as a reference and you will not
> be copying the data, but rather just creating an alias.
>
> For example:
>
> function &myFunction() {
> // create variable you don't want to copy around
> return $myVeryLargeVariable;
> }
>
> $myVeryLargeVariable =& myFunction();
Thanks for that. Seems to make some improvement... What you describe
above seems to cover returning by reference. Am I correct? If this is
the case, would the following bit of code :
$x = 2;
$y = 2;
$result =& return_result($x, $y);
print("RESULT is $result");
exit();
function &return_result($x, $y)
{
$result = $x + $y;
return($result);
}
allocate space for $result twice, or just the once?
Also, how would I pass references to x and y to the function instead
of passing x and y? If I pass x and y as I am in this example (and
yes, I know it's brane damiged(tm) because the variables are so small
references don't save me any memory), aren't I allocating memory for
them twice?
Thanks,
-- A Complete Luser <acompleteluser <email protected>>-- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe <email protected> For additional commands, e-mail: php-general-help <email protected> To contact the list administrators, e-mail: php-list-admin <email protected>
- Next message: Mukul Sabharwal: "Re: [PHP] How setcookie and header can be used together?"
- Previous message: Chad Day: "[PHP] Help with sessions and netscape."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

