note 34745 added to function.empty

From: Date: Tue, 05 Aug 2003 17:29:02 +0000
Subject: note 34745 added to function.empty
Groups: php.notes 
Request: Send a blank email to php-notes+get-53440@lists.php.net to get a copy of this message
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 ---- Manual Page -- http://www.php.net/manual/en/function.empty.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+34745 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+34745&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+34745&report=yes

« previous php.notes (#53440) next »