note 12160 rejected from function.unset by didou
| From: | didou@php.net | Date: | Tue, 19 Aug 2003 15:46:48 +0000 |
| Subject: | note 12160 rejected from function.unset by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-54687@lists.php.net to get a copy of this message | ||
Note Submitter: aulbach@unter.franken.de
----
The docs for unset() should be changed in the following way:
unset() destroys the specified variables. This means, that the REFERENCE to the VALUE is destroyed,
not the VALUE itself (in PHP4 every variable is a reference to a value, see chapter
"references"). PHP4 cleans up the VALUE memory automatically for you, if no references to
a value are left.
So be extremly careful if you unset() a variable with MORE THAN ONE REFERENCE. Cause unset() clears
only this reference, the remaining references are not cleared! This means, that this results in
different values for two vars which has been referenced to one value after unset()ing one of them.
The prefered way to tell PHP, that an referenced var should be cleared is to set it to the value
NULL. This will change the VALUE, and does not delete the REFERENCE. Be careful, there are
currently some (more or less undocumented) discrepancies left in PHP, which will have perhaps bad
side effects.
Please have a closer look to the "references"-chapter to understand what could happen.
PS: My personal opinion is, that PHP either lacks documentation or needs some discussion in the way
it interprets unset() and NULL and what will happen with NULL-values.