note 81703 deleted from function.unset by nlopess
| From: | nlopess@php.net | Date: | Mon, 10 Mar 2008 17:13:20 +0000 |
| Subject: | note 81703 deleted from function.unset by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-136908@lists.php.net to get a copy of this message | ||
Note Submitter: Kai Kunstmann
----
Since unset() is a language construct, it cannot be passed anything other than a variable. It's
sole purpose is to "unset" this variable, ie. to remove it from the current scope and
destroy it's associated data. This is true especially for reference variables, where not the
actual value is destroyed but the reference to that value. This is why you can't wrap
'unset()' in a user defined function: You would either unset a copy of the data if the
parameter is passed by value, or you would just unset the reference variable within the functions
scope if the parameter is passed by reference. There is no workaround for that, as you cannot pass
'scope' to a function in PHP. Such a function can only work for variables that exist in a
common or global scope (compare 'unset($_GLOBALS[variable])').
I don't know how PHP handles garbage collection internally, but I guess this behavior can
result in a huge memory leak: if a value variable goes out of scope with a second variable still
holding a reference to the in-memory value, then unsetting that reference would still hold the value
in memory but potentially unset the last reference to that in-memory data, hence: occupied memory
that is rendered useless as you cannot reference it anymore.