Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:58967 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 44300 invoked from network); 15 Mar 2012 17:41:28 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 15 Mar 2012 17:41:28 -0000 Authentication-Results: pb1.pair.com smtp.mail=dragoonis@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=dragoonis@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.217.170 as permitted sender) X-PHP-List-Original-Sender: dragoonis@gmail.com X-Host-Fingerprint: 209.85.217.170 mail-lb0-f170.google.com Received: from [209.85.217.170] ([209.85.217.170:52659] helo=mail-lb0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B3/26-16214-7C9226F4 for ; Thu, 15 Mar 2012 12:41:28 -0500 Received: by lbbgg13 with SMTP id gg13so1701376lbb.29 for ; Thu, 15 Mar 2012 10:41:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=RUPdoKY2pnoQ0x0c3PB4tJ9+Z+HK7Ll2Q01T2ZAs56E=; b=sHK4kPDHP3ax8FJOMB6kO+GXijUrjSvjG9si9ED+E5VIrsWhmUA65SMtjezJsw6cTC S9Sig1s/+3xciEoJOIe9bbWBKxn77dhLAz4D3FtqLh/ar2aaobL/5evdGdtpNGKnLqYo +0PtLVzLIuWt9dk/uXvPd+OdjxMIwmxmtoq+JqIlStrxMuV+HbQMEFHGqoZnvduVsav/ VQyA4dFAqNHebM0nkWBfYWjOWIq+K124Xkqy+Zt187w5UYX4Bc34RBVsnTSOrBXMNxtq 2AvSPBBIh3YW4qoIcsRHYj5qQXv2axOIc5/ZQlzey9jg6RftjeGYG7U8tdIKYXCP6fQW 7txw== MIME-Version: 1.0 Received: by 10.112.98.198 with SMTP id ek6mr2769373lbb.4.1331833284238; Thu, 15 Mar 2012 10:41:24 -0700 (PDT) Received: by 10.152.13.40 with HTTP; Thu, 15 Mar 2012 10:41:24 -0700 (PDT) In-Reply-To: References: Date: Thu, 15 Mar 2012 17:41:24 +0000 Message-ID: To: Nikita Popov Cc: Patrick ALLAERT , Klaus Silveira , PHP Internals Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Small question about performance From: dragoonis@gmail.com (Paul Dragoonis) On Thu, Mar 15, 2012 at 5:39 PM, Paul Dragoonis wrote= : > On Thu, Mar 15, 2012 at 4:54 PM, Nikita Popov = wrote: >> On Thu, Mar 15, 2012 at 5:22 PM, Patrick ALLAERT wrote: >>> 2012/3/15 Nikita Popov : >>>> If I am understanding the text correctly it is saying that >>>> =A0 =A0$f1 =3D f1(); >>>> =A0 =A0$f2 =3D f2($f1); >>>> =A0 =A0$f3 =3D f3($f2); >>>> is using more memory than >>>> =A0 =A0$f3 =3D 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(). >> I don't really know when PHP frees temporary variables, but my guess >> was that they are freed when the scope is left. > > Each variable has a refcount, then that hits 0 it can be freed up. To add to that. A zval will have a refcount, so if you do $a =3D someFunc(); then $a will have a refcount. If you do something like $a =3D someFunc(anotherFunc(moreFunc())), the return values of anotherFunc() and moreFunc() will be temp stored, but they will _not_ have a refcount because they never got assigned into a zval like $a. Hope that made sense. > >> >> If that is not true, then forget whatever I said. >> >> But if it is true, then there is no inherent difference between the >> two version. The only difference is that explicit $variables would >> need an entry in the active symbol table, which is pretty much >> negligible. >> >> -- >> PHP Internals - PHP Runtime Development Mailing List >> To unsubscribe, visit: http://www.php.net/unsub.php >>