note 106342 added to language.references.unset
| From: | Peter at osu1 dot php dot net | Date: | Sat, 29 Oct 2011 09:01:35 +0000 |
| Subject: | note 106342 added to language.references.unset | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-184211@lists.php.net to get a copy of this message | ||
The claim that unset does not work on objects does not appear to be correct to me (lowlight 20 Sep
11) as the following code shows:
$a = new stdclass();
$a->something = true;
unset($a);
var_dump($a); // $a is now undefined as one would expect.
I think that there is a problem with the code given in the previous post:
function test(&$trash)
{
unset($trash);
}
$a = new stdclass();
$a->something = true;
test($a);
var_dump($a); // $a is still defined (and unchanged).
My best understanding (guess?) of why the unset in the function call does not work is that the
'unset($trash)' line unbinds the $trash parameter from $a in much the same way that the
test_rebind function (below) would remove the binding between $trash and $a and replace it with a
binding to $GLOBALS and not cause a binding between $a and $GLOBALS.
function test_rebind(&$trash)
{
$trash = $GLOBALS;
}
An additional comment on the nuke_me function presented is that the object property
'something' is unset but the object '$a' is still defined which, I presume, was
not the intention of the code.
----
Server IP: 69.147.83.197
Probable Submitter: 88.97.22.61
----
Manual Page -- http://www.php.net/manual/en/language.references.unset.php
Edit -- https://master.php.net/note/edit/106342
Del: integrated -- https://master.php.net/note/delete/106342/integrated
Del: useless -- https://master.php.net/note/delete/106342/useless
Del: bad code -- https://master.php.net/note/delete/106342/bad+code
Del: spam -- https://master.php.net/note/delete/106342/spam
Del: non-english -- https://master.php.net/note/delete/106342/non-english
Del: in docs -- https://master.php.net/note/delete/106342/in+docs
Del: other reasons-- https://master.php.net/note/delete/106342
Reject -- https://master.php.net/note/reject/106342
Search -- https://master.php.net/manage/user-notes.php