Re: Confusing pointers in PHP 4 and 5
| From: | Bert Slagter | Date: | Wed, 09 Jun 2004 07:25:04 +0000 |
| Subject: | Re: Confusing pointers in PHP 4 and 5 | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-10332@lists.php.net to get a copy of this message | ||
Sara Golemon wrote:
Every "variable" in PHP is a pair. [cut] $foo = 1;Thanks for the clear explanation :). I understood that in PHP 5 objects are automatically referenced when assigned, and 'primary types' like int, bool, string are normally copied when assigned. When I do a (very rough) benchmark with strings/ints, assigning (and thus copying) a 1000 bytes string isn't significantly slower than referencing it. Also: memory usage is exactly the same. Is there any situation in which one might *manually* want to reference a variable instead of assigning it (like: $x =& $y)? Bert/* $foo (label) --------> 1 (value) (is_ref=0, refcount=1) */$bar = &$foo;/* $foo (label) ----------> 1 (value) */ /* $bar (label) -------/ is_ref=1, refcount=2 */Hope that helps. -Sara