Oh the Shame [moved]
-
Is this forum replacing "subtle bugs'? Anyway I was just starting with PHP and wrote a function that validated a form that was submitted. The function returned "true" (not string, boolean true) if everything checked out and an error description if something was wrong. I then had a switch case for the result:
//Something like:
switch($isValid){case true:
echo 'Valid data';
break;case 'email'
echo 'Invalid Email';
break;/*
An so on and so forth
*/
}Now you can imagine my surprise when every case returned "Valid data". Took me about 15 minutes to spot that.
Brad Australian - Captain See Sharp on "Religion" any half intelligent person can come to the conclusion that pink unicorns do not exist.
-- moved by Ed. at 12:20 Sunday 4th March, 2007
-
Is this forum replacing "subtle bugs'? Anyway I was just starting with PHP and wrote a function that validated a form that was submitted. The function returned "true" (not string, boolean true) if everything checked out and an error description if something was wrong. I then had a switch case for the result:
//Something like:
switch($isValid){case true:
echo 'Valid data';
break;case 'email'
echo 'Invalid Email';
break;/*
An so on and so forth
*/
}Now you can imagine my surprise when every case returned "Valid data". Took me about 15 minutes to spot that.
Brad Australian - Captain See Sharp on "Religion" any half intelligent person can come to the conclusion that pink unicorns do not exist.
-- moved by Ed. at 12:20 Sunday 4th March, 2007
Bradml wrote:
Is this forum replacing "subtle bugs'?
I believe no. Subtle bugs forum is for bugs that were hard to discover, but were fixed. You should not feel ashamed of posting such bugs. Hall of Shame forum is for bugs that could be considered (unforced errors) in Tennis world. An experienced developer should never make such bugs before 2AM. One should feel ashamed when posting such a bug, but it's OK. All your fellow developers had such bugs.
Hesham A. Amin blog
-
Is this forum replacing "subtle bugs'? Anyway I was just starting with PHP and wrote a function that validated a form that was submitted. The function returned "true" (not string, boolean true) if everything checked out and an error description if something was wrong. I then had a switch case for the result:
//Something like:
switch($isValid){case true:
echo 'Valid data';
break;case 'email'
echo 'Invalid Email';
break;/*
An so on and so forth
*/
}Now you can imagine my surprise when every case returned "Valid data". Took me about 15 minutes to spot that.
Brad Australian - Captain See Sharp on "Religion" any half intelligent person can come to the conclusion that pink unicorns do not exist.
-- moved by Ed. at 12:20 Sunday 4th March, 2007
Even JavaScript "true" is treated as string I guess. :)
Vasudevan Deepak Kumar Personal Homepage Tech Gossips
-
Even JavaScript "true" is treated as string I guess. :)
Vasudevan Deepak Kumar Personal Homepage Tech Gossips
-
Is this forum replacing "subtle bugs'? Anyway I was just starting with PHP and wrote a function that validated a form that was submitted. The function returned "true" (not string, boolean true) if everything checked out and an error description if something was wrong. I then had a switch case for the result:
//Something like:
switch($isValid){case true:
echo 'Valid data';
break;case 'email'
echo 'Invalid Email';
break;/*
An so on and so forth
*/
}Now you can imagine my surprise when every case returned "Valid data". Took me about 15 minutes to spot that.
Brad Australian - Captain See Sharp on "Religion" any half intelligent person can come to the conclusion that pink unicorns do not exist.
-- moved by Ed. at 12:20 Sunday 4th March, 2007
So you compare a string with a bool - doesn't that cause an implicit conversion? It's long ago that I used PHP, but it might be strange enough to convert every non-empty string to true (instead of the more obvious conversion: converting the bool to string). I remember something about the === operator for comparisons with true/false as error codes to prevent implicit conversions, switch probably only uses ==. Also, you forgot the ':' after case 'email'.