Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:10332 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 27075 invoked by uid 1010); 9 Jun 2004 07:24:55 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 27051 invoked by uid 1007); 9 Jun 2004 07:24:55 -0000 Message-ID: <20040609072455.27050.qmail@pb1.pair.com> To: internals@lists.php.net Date: Wed, 09 Jun 2004 09:25:04 +0200 User-Agent: Mozilla Thunderbird 0.6 (Windows/20040502) X-Accept-Language: en MIME-Version: 1.0 References: <20040608091715.6553.qmail@pb1.pair.com> <20040608185216.38360.qmail@pb1.pair.com> In-Reply-To: <20040608185216.38360.qmail@pb1.pair.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Posted-By: 80.126.99.118 Subject: Re: Confusing pointers in PHP 4 and 5 From: bert@procurios.nl (Bert Slagter) 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