note 82942 added to function.empty
| From: | GregHartwig at osu1 dot php dot net | Date: | Fri, 02 May 2008 21:55:25 +0000 |
| Subject: | note 82942 added to function.empty | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-139008@lists.php.net to get a copy of this message | ||
David from CodeXplorer:
>> The ONLY reason to use empty() is for code readability. It is the same as an IF/ELSE check.
>> So, don't bother using EMPTY in the real world.
This is NOT true. empty() will not generate warnings if you're testing against an undefined
variable as a simple boolean check will. On production systems, warnings are usually shut off, but
they are often active on development systems.
You could test a flag with
<?php if ($flagvar) ... ?>
but this can generate a warning if $flagvar is not set.
Instead of
<?php if (isset($flagvar) && $flagvar) ... ?>
you can simply use
<?php if (!empty($flagvar)) ... ?>
for easy readability without warnings.
----
Server IP: 208.69.120.35
Probable Submitter: 72.64.121.121
----
Manual Page -- http://www.php.net/manual/en/function.empty.php
Edit -- https://master.php.net/note/edit/82942
Del: integrated -- https://master.php.net/note/delete/82942/integrated
Del: useless -- https://master.php.net/note/delete/82942/useless
Del: bad code -- https://master.php.net/note/delete/82942/bad+code
Del: spam -- https://master.php.net/note/delete/82942/spam
Del: non-english -- https://master.php.net/note/delete/82942/non-english
Del: in docs -- https://master.php.net/note/delete/82942/in+docs
Del: other reasons-- https://master.php.net/note/delete/82942
Reject -- https://master.php.net/note/reject/82942
Search -- https://master.php.net/manage/user-notes.php