Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:10333 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 7625 invoked by uid 1010); 9 Jun 2004 08:13:34 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 7491 invoked by uid 1007); 9 Jun 2004 08:13:33 -0000 Message-ID: <20040609081333.7480.qmail@pb1.pair.com> To: internals@lists.php.net References: <20040608091715.6553.qmail@pb1.pair.com> <20040608185216.38360.qmail@pb1.pair.com> <20040609072455.27050.qmail@pb1.pair.com> Date: Wed, 9 Jun 2004 18:13:35 +1000 Lines: 40 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1409 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409 X-Posted-By: 144.132.77.145 Subject: Re: Confusing pointers in PHP 4 and 5 From: aidan@php.net ("Aidan Lister") I think, and I could be completely wrong, that copying a variable actually creates a reference. The data is only copied when the variable referenced is modified. "Bert Slagter" wrote in message news:20040609072455.27050.qmail@pb1.pair.com... > Sara Golemon wrote: > > Every "variable" in PHP is a pair. > > > > [cut] > > > > $foo = 1; > > > > /* $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 > > 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