Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:19970 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 6971 invoked by uid 1010); 14 Nov 2005 07:34:55 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 6956 invoked from network); 14 Nov 2005 07:34:55 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 14 Nov 2005 07:34:55 -0000 X-Host-Fingerprint: 195.225.34.5 fw01.axit.nl Received: from ([195.225.34.5:22642] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.0 beta r(6323M)) with SMTP id 18/BA-07637-E1E38734 for ; Mon, 14 Nov 2005 02:34:54 -0500 Message-ID: <18.BA.07637.E1E38734@pb1.pair.com> To: internals@lists.php.net References: <1131730140.30983.2.camel@ganges.spikesource.com> Date: Mon, 14 Nov 2005 08:33:08 +0100 Lines: 45 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2670 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670 X-RFC2646: Format=Flowed; Original X-Posted-By: 195.225.34.5 Subject: Re: Array_merge, safety and race condition? From: r.korving@xit.nl ("Ron Korving") Now I'm no core developer, but I think what you fear is impossible. If I'm not mistaken: array_merge() will write it's result to a piece of data and when it's finished, it will make $array1 point to it, as I expect this to work in every function that returns something. Ron "Ezra Nugroho" schreef in bericht news:1131730140.30983.2.camel@ganges.spikesource.com... >I sent this to the general list, but I didn't get definitive answer. > Maybe internals is the better forum to talk about it. > If you have a test code, or other pointers towards a definitive answer, > I'd love to try it. > > Thanks > > > > > Php experts everywhere, > > I want to merge two arrays, and I want to store the result as the first > array. Something like the following: > > > $array1 = array_merge ($array1, $array2); > > > So far the code gives me what I want. However, suppose if $array1 is > extremely huge, am I introducing a bug here because of possible race > condition? It's possible that array_merge has two write something to > $array1 (left hand side) before it even finishes reading it (argument) > in the first place. Let alone merging the two. > > Should I just go conservative and do: > > $tmp = array_merge($array1, $array2); > $array1 = $tmp; > > > Thank you, > Ezra