note 97535 added to function.strlen
| From: | php at bucksvsbytes dot com | Date: | Sat, 24 Apr 2010 20:59:26 +0000 |
| Subject: | note 97535 added to function.strlen | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-168603@lists.php.net to get a copy of this message | ||
As noted below (01-Jul-2007), you can use strlen() to determine if an expression has content, i.e.
is anything (including object, array, resource) other than null or the empty string. This works
because, for non-strings, strlen() returns the length of the string conversion of the expression, so
it is non-zero for most non-strings:
strlen($array)=5 because (string)@array='Array'
strlen($resource) is about 14 because (string)$resource is of the form 'Resource id #9'
Exception: strlen($object) causes a fatal error unless the class has the __toString method defined,
so you have to test is_object($object) before strlen().
Result:
(is_object($expression)||strlen($expression)) is false only if $expression is null or the empty
string
----
Server IP: 69.147.83.197
Probable Submitter: 71.169.17.211
----
Manual Page -- http://www.php.net/manual/en/function.strlen.php
Edit -- https://master.php.net/note/edit/97535
Del: integrated -- https://master.php.net/note/delete/97535/integrated
Del: useless -- https://master.php.net/note/delete/97535/useless
Del: bad code -- https://master.php.net/note/delete/97535/bad+code
Del: spam -- https://master.php.net/note/delete/97535/spam
Del: non-english -- https://master.php.net/note/delete/97535/non-english
Del: in docs -- https://master.php.net/note/delete/97535/in+docs
Del: other reasons-- https://master.php.net/note/delete/97535
Reject -- https://master.php.net/note/reject/97535
Search -- https://master.php.net/manage/user-notes.php