considering that the variable only can be String fetched from an HTML Form (input-text, textarea).
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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.
回答2:
$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)
回答3:
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.