note 86816 added to function.unset
| From: | thijsNOSPACEputmanatgmaildotcom at osu1 dot php dot net | Date: | Wed, 05 Nov 2008 01:17:18 +0000 |
| Subject: | note 86816 added to function.unset | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-146147@lists.php.net to get a copy of this message | ||
"It is possible to unset even object properties visible in current context"
Although the note is clear, in my case it required a little example to grasp its full impact:
If your object uses overloaded properties (using the "__set()" magic method) and you unset
one of your "real" properties, the "__set()" method will take over if you try to
assign a value to this property again.
In most cases, the "__set()" method is very much limited in the properties it can set. In
my case, I only allow "__set()" to change a limited, predefined, set of properties. Most
of them through their "public" name instead of their actual name...
This generates a somewhat counter-intuitive situation: If you unset a variable, you expect its value
to become "null", which remains true. You also expect to be able to set it again to
another value.
In the example described above this is not the case: The "__get()" method is invoked and,
in my case, doesn't allow the property to be set again!
----
Server IP: 69.147.83.197
Probable Submitter: 145.120.14.168
----
Manual Page -- http://www.php.net/manual/en/function.unset.php
Edit -- https://master.php.net/note/edit/86816
Del: integrated -- https://master.php.net/note/delete/86816/integrated
Del: useless -- https://master.php.net/note/delete/86816/useless
Del: bad code -- https://master.php.net/note/delete/86816/bad+code
Del: spam -- https://master.php.net/note/delete/86816/spam
Del: non-english -- https://master.php.net/note/delete/86816/non-english
Del: in docs -- https://master.php.net/note/delete/86816/in+docs
Del: other reasons-- https://master.php.net/note/delete/86816
Reject -- https://master.php.net/note/reject/86816
Search -- https://master.php.net/manage/user-notes.php