I was looking at some form validation code someone else had written and I saw this:
strlen() == 0
When testing to see if a form variable is empty I use the empty()
function. Is one way better than the other? Are they functionally equivalent?
There are a couple cases where they will have different behaviour:
empty('0'); // returns true,
strlen('0'); // returns 1.
empty(array()); // returns true,
strlen(array()); // returns null with a Warning in PHP>=5.3 OR 5 with a Notice in PHP<5.3.
empty(0); // returns true,
strlen(0); // returns 1.