RE: [PEAR-DEV] references
| From: | Chuck Hagenbuch | Date: | Fri, 15 Aug 2003 16:21:22 +0000 |
| Subject: | RE: [PEAR-DEV] references | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-19828@lists.php.net to get a copy of this message | ||
Quoting Lukas Smith <smith@backendmedia.com>:
> $foo = 'foo'; ('foo' in memory, ref counter 1)
> $bar = $foo; ('foo' in memory, ref counter 2)
> $bar = 'bar' ('foo' and 'bar' in memory, each with ref counter 1)
>
> the point is that in the second line you don't actually make a copy yet.
> Only once you change the value a new var is really created
>
> the same applies to passing values to a function.
> Because if this mechanism pass by reference is actually slower than not
> using it. Therefore pass by reference should only be used if you really
> need it.
Does this apply to returning values by reference, too?
For instance:
function &buildBigArray()
{
// do stuff that builds up $hugeVariable
return $hugeVariable;
}
$huge = &buildBigArray();
Better or worse with returning a reference? For this example, assume that $huge
will never be modified, though I'm curious about if it is, too.
-chuck
--
Charles Hagenbuch, <chuck@horde.org>
They're just looking at a wall of meat.