Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:58970 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 78233 invoked from network); 15 Mar 2012 19:10:28 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 15 Mar 2012 19:10:28 -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:60484] helo=mail-iy0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 0D/8D-16214-3AE326F4 for ; Thu, 15 Mar 2012 14:10:28 -0500 Received: by iaeh11 with SMTP id h11so5049512iae.29 for ; Thu, 15 Mar 2012 12:10:25 -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=o99eJGhMKR0omMai8C+aZ4Bgapl3k3YyXdm/DeHGQng=; b=irOXi739MXX88J9y0BSrAkDheiUu46NJ39Yh70av0rdS7Tb8nUIEEJxUXpl3lZcy+2 Jo41EEZ6psQd9h4e+oTKskUPFozmKcjhhV7FXoUBBFj8T3kAuHiILBfOUeGSKEqHvgNF 5hHBdUDbhtAihc3advdJCFuichgfhYKCchzAabmVbu/N5yEt7tMAo/LUG9dLFwojNL6R R8bBAnxTOgvgUvEX4aSfITFF4G1AgtuXbpKgq3nD491M1rFFWSZGK8gJXrS/n9lGFK3D JuGWX76IazrqVYN6K/xWTfp4RPZFdJyh9QiW/q+rD2rmjHbMnOKb2im/uQsPsPw7d1YL ObXg== Received: by 10.42.138.9 with SMTP id a9mr8677419icu.14.1331838625178; Thu, 15 Mar 2012 12:10:25 -0700 (PDT) MIME-Version: 1.0 Sender: mikegstowe@gmail.com Received: by 10.50.188.197 with HTTP; Thu, 15 Mar 2012 12:10:04 -0700 (PDT) In-Reply-To: <4F623BD1.4080009@thelounge.net> References: <4F623BD1.4080009@thelounge.net> Date: Thu, 15 Mar 2012 14:10:04 -0500 X-Google-Sender-Auth: wqiEyorOE0BLImbX6Y2EnWJkEeA Message-ID: To: Reindl Harald Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary=90e6ba6e86ea26e33c04bb4cd898 Subject: Re: [PHP-DEV] Small question about performance From: me@mikestowe.com (Michael Stowe) --90e6ba6e86ea26e33c04bb4cd898 Content-Type: text/plain; charset=ISO-8859-1 The $b on this example would be freed as it is in the function's scope, and not the global scope. The exception to this would be a static variable within a function, which would persist for future use within the function. Class properties on the other hand will persist until the object is destructed, or until they are unset. So for your example, function test() { $b = 'apple'; return $b; } You would not need to unset $b as it resides temporarily within the function, and does not persist outside of the function. - Mike On Thu, Mar 15, 2012 at 1:58 PM, Reindl Harald wrote: > > > Am 15.03.2012 18:41, schrieb Paul Dragoonis: > >>> 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 = > > someFunc(); then $a will have a refcount. > > > > If you do something like $a = 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. > > to make sure i understand this really > > function myfunc() > { > $b = internal_function_with_hughe_return_value(); > return false; > } > > $b is freed after the function has finished > if not i should write a lot of unset() what > is not possible if you have return $b > > > > > -- ----------------------- "My command is this: Love each other as I have loved you." John 15:12 ----------------------- --90e6ba6e86ea26e33c04bb4cd898--