note 81702 added to function.unset
| From: | KaiKunstmann at osu1 dot php dot net | Date: | Mon, 10 Mar 2008 13:09:06 +0000 |
| Subject: | note 81702 added to function.unset | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-136902@lists.php.net to get a copy of this message | ||
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.
----
Server IP: 69.147.83.197
Probable Submitter: 84.179.180.62
----
Manual Page -- http://www.php.net/manual/en/function.unset.php
Edit -- https://master.php.net/note/edit/81702
Del: integrated -- https://master.php.net/note/delete/81702/integrated
Del: useless -- https://master.php.net/note/delete/81702/useless
Del: bad code -- https://master.php.net/note/delete/81702/bad+code
Del: spam -- https://master.php.net/note/delete/81702/spam
Del: non-english -- https://master.php.net/note/delete/81702/non-english
Del: in docs -- https://master.php.net/note/delete/81702/in+docs
Del: other reasons-- https://master.php.net/note/delete/81702
Reject -- https://master.php.net/note/reject/81702
Search -- https://master.php.net/manage/user-notes.php