Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:58963 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 22633 invoked from network); 15 Mar 2012 16:34:01 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 15 Mar 2012 16:34:01 -0000 Authentication-Results: pb1.pair.com header.from=mikegstowe@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=mikegstowe@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.210.170 as permitted sender) X-PHP-List-Original-Sender: mikegstowe@gmail.com X-Host-Fingerprint: 209.85.210.170 mail-iy0-f170.google.com Received: from [209.85.210.170] ([209.85.210.170:52126] helo=mail-iy0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 3C/61-16214-8F9126F4 for ; Thu, 15 Mar 2012 11:34:01 -0500 Received: by iaeh11 with SMTP id h11so4846602iae.29 for ; Thu, 15 Mar 2012 09:33:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date :x-google-sender-auth:message-id:subject:to:cc:content-type; bh=+DvolH+YVZ4Jjh8OiduCI+PfNleylMrdn6j5kcSEp6A=; b=agERuZ6nSFL1EB+QlBAbpF3dEYWKaVSjAMNkIMB0BqWNmAGbhXobZ+ZIngpOd4mjHo yoOy8Kx/wg/lSEGrG+B3CFvzDab8hGy0NCiItC1S+ywU7rxzqWc6xA8WCOSqdlXmsKKU Y2MMm/QfiZgraQDLk5VN/7/k0xcmpEaq8YqlDHNLPyfOYUyFVuuGqHVQoTVUr8XWS3/w cpEqkiXK0Kc4TaWZ1y4kp/302nNPAAcW0707mfl/ME/fstIXOPUtIX4NAf+1le1JI8gg D0xedGLn8WZbNuyG2EExxwcSEFRKWdsKm6MUha4PyburFAh3aElMNJ8EwLueXs8b6fDp /D+w== Received: by 10.50.185.138 with SMTP id fc10mr10484728igc.6.1331829234765; Thu, 15 Mar 2012 09:33:54 -0700 (PDT) MIME-Version: 1.0 Sender: mikegstowe@gmail.com Received: by 10.50.188.197 with HTTP; Thu, 15 Mar 2012 09:33:34 -0700 (PDT) In-Reply-To: References: Date: Thu, 15 Mar 2012 11:33:34 -0500 X-Google-Sender-Auth: 38lAxhbPZ0gIpkPBxf4WrAtOhL0 Message-ID: To: Patrick ALLAERT Cc: Nikita Popov , Klaus Silveira , PHP Internals Content-Type: multipart/alternative; boundary=14dae934105370919604bb4aa887 Subject: Re: [PHP-DEV] Small question about performance From: me@mikestowe.com (Michael Stowe) --14dae934105370919604bb4aa887 Content-Type: text/plain; charset=ISO-8859-1 Just to elaborate on what Patrick said, in the first case the variables are temporary, where in the second they persist even after you finish your loop. So even after the foreach is finished, the $f1, $f2, and $f3 variables are still storing data- even though it is no longer needed. In order to free up the memory allocated to these variables you'd have to unset them after they're used in the loop, or after the loop has finished. - Mike On Thu, Mar 15, 2012 at 11:22 AM, Patrick ALLAERT wrote: > 2012/3/15 Nikita Popov : > > If I am understanding the text correctly it is saying that > > $f1 = f1(); > > $f2 = f2($f1); > > $f3 = f3($f2); > > is using more memory than > > $f3 = f3(f2(f1())); > > > > For me this doesn't make any sense. In the latter case PHP will also > > create temporary variables to store the return values. There should be > > no difference in memory consumption. > > It does make sense to me. > > In the first case, when calling f3(), $f1 is still referenced. > In the second case, when calling f3(), the result of f2() is > referenced, but there is no more active reference to the result of > f1(). > > Regarding the original problem: > foreach($a as $key => $val) { > $a[$key] = someLong(functionCalls(hereThat($spanOver85Chars))); > } > > Sounds easier to split over lines without temporary zvals: > foreach($a as $key => $val) { > $a[$key] = someLong( > functionCalls( > hereThat( > $spanOver85Chars > ) > ) > ); > } > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > -- ----------------------- "My command is this: Love each other as I have loved you." John 15:12 ----------------------- --14dae934105370919604bb4aa887--