Passing by references

From: Date: Sun, 24 Dec 2000 02:38:49 +0000
Subject: Passing by references
Groups: php.general 
Request: Send a blank email to php-general+get-31728@lists.php.net to get a copy of this message
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@penguinpowered.org.uk>

« previous php.general (#31728) next »