note 97535 deleted from function.strlen by danbrown

From: Date: Sat, 24 Apr 2010 22:14:44 +0000
Subject: note 97535 deleted from function.strlen by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-168604@lists.php.net to get a copy of this message
Note Submitter: php at bucksvsbytes dot com ---- 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

« previous php.notes (#168604) next »