note 34745 deleted from function.empty by didou
| From: | didou@php.net | Date: | Tue, 05 Aug 2003 19:03:41 +0000 |
| Subject: | note 34745 deleted from function.empty by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-53443@lists.php.net to get a copy of this message | ||
Note Submitter: bishop
----
If you're not ABSOLUTELY sure you should be using empty(), DON'T; it has caveats that are
non-obvious.
If you're interested in testing whether a string is empty (i.e., lambda), then use something
like:
function empty_string($str) {
return (isset($str) && is_string($str) && strspn($str, " \t\n\r\f")
=== strlen($str));
}
Examples:
string(0) "" is empty string
string(1) " " is empty string
string(3) "foo" is not empty string
int(1) is not empty string
string(2) " 1" is not empty string
int(0) is not empty string
array(0) { } is not empty string
bool(false) is not empty string
bool(true) is not empty string
NULL is not empty string