Hi,
considering that the variable only can be String fetched from an HTML Form (input-text, textarea).
views:
51answers:
3
+1
A:
Yes, there is a difference between strlen($str)==0
and empty($str)
. empty
returns true if the value is "0"
. See the PHP type comparison tables.
Gumbo
2009-08-23 11:35:06
+1
A:
$var = 0;
strlen( $var ); // 1, coerced to true
empty($var) // true, it's considered "empty", these are the empty ones:
- "" (an empty string)
- 0 (0 as an integer)
- "0" (0 as a string)
- NULL
- FALSE
- array() (an empty array)
- var $var; (a variable declared, but without a value in a class)
meder
2009-08-23 11:35:23
A:
Here is some note I've discovered:
empty(), requires a variable and only a variable, so I think it has a problem when it's dealing with an object value fetched from the magic __get() method.
Omar Dolaimy
2009-08-24 10:44:58