note 72508 deleted from function.empty by didou
| From: | didou@php.net | Date: | Sun, 18 May 2008 00:56:36 +0000 |
| Subject: | note 72508 deleted from function.empty by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-139477@lists.php.net to get a copy of this message | ||
Note Submitter: Stephen
----
I wanted to correct a couple of errors in some earlier user notes, regarding which is better, using
empty() within an if clause to be evaluated, or using only the variable. E.g.:
if (!$blah)
versus
if (empty($blah))
or
if ($blah)
versus
if (!empty($blah))
First, one person noted that empty() is basically worthless because you don't need it to do the
above functionality. However, I think this is wrong for 2 reasons:
1. It is needed for arrays and (I think) objects
2. empty() is actually FASTER than using just the variable. You might think that it would be slower
because it looks like a function, but it is actually a language construct. Apparently it is
optimized. It is at least 10% faster, sometimes nearly 20% faster.
Second, one person claimed that if you don't use empty, and just test the variable, you will
get an E_WARNING error. I don't know if this used to be true, but for me in PHP 5.2, it only
generates an E_NOTICE.
I hope this clears up somebody's confusion.