note 111576 added to function.unset
| From: | HayleyWatson | Date: | Tue, 05 Mar 2013 21:41:51 +0000 |
| Subject: | note 111576 added to function.unset | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-193949@lists.php.net to get a copy of this message | ||
You don't need to check that a variable is set before you unset it.
<?php
unset($a);
?>
is harmless.
<?php
if(isset($a)) {
unset($a);
}
?>
is pointless complication.
This doesn't apply to properties of objects that have __isset() methods that visibly change
object state or __unset() methods that don't properly check their arguments or have extra side
effects.
The latter case means that __unset shouldn't do more than what it says on the tin, and also has
the responsibility for checking (possibly using __isset()) that what it's being asked to do
makes sense.
The former case is just plain bad design.
----
Server IP: 69.147.83.199
Probable Submitter: 202.175.135.150
----
Manual Page -- http://php.net/manual/en/function.unset.php
Edit -- https://master.php.net/note/edit/111576
Del: integrated -- https://master.php.net/note/delete/111576/integrated
Del: useless -- https://master.php.net/note/delete/111576/useless
Del: bad code -- https://master.php.net/note/delete/111576/bad+code
Del: spam -- https://master.php.net/note/delete/111576/spam
Del: non-english -- https://master.php.net/note/delete/111576/non-english
Del: in docs -- https://master.php.net/note/delete/111576/in+docs
Del: other reasons-- https://master.php.net/note/delete/111576
Reject -- https://master.php.net/note/reject/111576
Search -- https://master.php.net/manage/user-notes.php