Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:18956 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 32542 invoked by uid 1010); 15 Sep 2005 11:15:08 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 32527 invoked from network); 15 Sep 2005 11:15:08 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 15 Sep 2005 11:15:08 -0000 X-Host-Fingerprint: 80.74.107.235 mail.zend.com Linux 2.5 (sometimes 2.4) (4) Received: from ([80.74.107.235:40633] helo=mail.zend.com) by pb1.pair.com (ecelerity 2.0 beta r(6323M)) with SMTP id 0C/BE-41173-BB759234 for ; Thu, 15 Sep 2005 07:15:08 -0400 Received: (qmail 24276 invoked from network); 15 Sep 2005 11:15:03 -0000 Received: from localhost (HELO zeev-notebook.zend.com) (127.0.0.1) by localhost with SMTP; 15 Sep 2005 11:15:03 -0000 Message-ID: <5.1.0.14.2.20050915141221.0605b540@localhost> X-Sender: zeev@localhost X-Mailer: QUALCOMM Windows Eudora Version 5.1 Date: Thu, 15 Sep 2005 14:15:02 +0300 To: "Ron Korving" Cc: internals@lists.php.net In-Reply-To: <81.1E.41173.93F49234@pb1.pair.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed Subject: Re: [PHP-DEV] references in arrays From: zeev@zend.com (Zeev Suraski) References: <81.1E.41173.93F49234@pb1.pair.com> At 13:35 15/09/2005, Ron Korving wrote: >Hi, > >For performance' sake, I have to know if this is true: > >Is it the case that when I do this: > > $array = array("one" => array(0,1,2), "two" => array(4,5,6)); > $one = $array["one"]; >?> > >That $one is not a copy, but a reference to $array["one"] and will only >become a copy when I alter the contents of $one? That's correct. >I know this is the case for >regular variables, but does this also go for contents of arrays? If not, I >need to use the ampersand like I used to. But if it really is just a >reference, that would be good to know as I shouldn't be using the ampersand >at all (mistakingly thinking it's a performance advantage when it's actually >not). Generally, using & where it's not necessary is more often than not a performance disadvantage, and not an advantage. You should never use & for better performance, only if you need it for applicative usage. The engine would do its best to do the least copying on its own. Zeev