views:

51

answers:

3

Hi,
considering that the variable only can be String fetched from an HTML Form (input-text, textarea).

+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
+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
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