RE: [PEAR-DEV] references
| From: | Lukas Smith | Date: | Fri, 15 Aug 2003 16:36:25 +0000 |
| Subject: | RE: [PEAR-DEV] references | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-19832@lists.php.net to get a copy of this message | ||
> From: Chuck Hagenbuch [mailto:chuck@horde.org]
> Sent: Friday, August 15, 2003 6:21 PM
>
> 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?
I dont know all the ins and outs of it, but I would assume it would. For
all I know you should only really use pass by reference for passing
objects if you want to ensure that they are not copied.
Here are two articles that might offer some answers:
http://www.zend.com/zend/art/ref-count.php
http://phplens.com/lens/php-book/optimizing-debugging-php.php
regards,
Lukas