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 <h.rei...@thelounge.net>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 -----------------------