[PHP] Passing by references From: A Complete Luser (acompleteluser <email protected>)
Date: 12/23/00

I've read the section of the php manual on references and found it a
bit hard to follow. I am trying to clear the following up in my head.

How do references work? the manual says that they are not like C
pointers, but more like hardlinking in a file system... What does this
mean for memory in an application where you have a large chunk of data
that you want to pass back and forth to various functions in various
library's?

What I am doing at the moment is building an array of values in a
function and then returning that array.

AFAIK, this means that I am making a copy of that array, thus using
double the amount of memory that I require. For a small group of
users, this isn't a problem, but on a bigger system, this will hurt
me.

What I want to do, is to build the array in the function, and then
return a pointer / reference to that array to the calling
function. Then the calling function could access the values without
having to make another copy in memory. The same goes for passing
values to functions. I would like the calling function to pass
references, not the actual values. So for example, instead of

$result = foo($string1, $string2, $string3)

function foo($string1, $string2, $string3)
{
     $array[0] = $string1;
     $array[1] = $string2;
     $array[2] = $string3;
     
     return($array);
}

I would pass pointers to string1, string2 and string3 to function foo,
and then receive a pointer to the array containing the result. The
example above is a dumb example, with no need to use a function, but
it's the easist way I can illustrate my point.

Is what I want to do possible? if so, could someone please point me to
where?

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>