I often see strlen used. Are these 2 tests equivalent for all values of $str?
is_string($str) && 0 !== strlen($str)
is_string($str) && '' !== $str
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes, those two statements are logically equivalent. My preferred ways to skin this cat:
…though
empty('0')istrue(sigh, PHP…), so this is probably even better:See also: Checking if the string is empty and Is there a difference between $str == '' and strlen($str) == 0 in PHP?