note 41688 added to language.references.unset
| From: | bishop at rn2 dot php dot net | Date: | Mon, 19 Apr 2004 23:31:08 +0000 |
| Subject: | note 41688 added to language.references.unset | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-68348@lists.php.net to get a copy of this message | ||
The unset() behaviour on a referenced variable is very strange and quite counter-intuitive.
Consider:
<?php
$orig = 1;
$ref = &$orig;
// ref is &int(1)
unset($orig);
// ref is int(1)
// NOTE the reference is gone, but the content remains
?>
A small workaround is to null your variables, then to unset them. Eg:
<?php
$orig = null;
unset($orig);
?>
This will at least prevent the original value from propogating to the uncoupled reference.
----
Manual Page -- http://www.php.net/manual/en/language.references.unset.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+41688
Delete -- http://master.php.net/manage/user-notes.php?action=delete+41688&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+41688&report=yes
Search -- http://master.php.net/manage/user-notes.php