How NOT to Code - Example 4

Jan 13, 2010

Ok, this is one is more difficult. Try to run the following code on Adobe's flavor of ColdFusion (doesn't matter which edition) and then determine the cause of the result. You were expecting 'false' right ;)

<cfif "00" eq "0a">


Richard Davies

Richard Davies wrote on 01/13/102:09 PM

Wow! This one really had me baffled. I had no idea what could possibly explain this odd behavior. Finally I had to resort to Google to figure it out. (I won't spoil it here for everyone else...)

This is good to know. Thanks for pointing it out.
John Sieber

John Sieber wrote on 01/13/102:43 PM

I cheated as well but it allowed me to learn something new today. The Adobe Live Docs have a good example.

Andrew wrote on 01/13/104:52 PM

lol! yah, that's a new one. good to know! :) thanks!

(hint: think 'time')
John Mason

John Mason wrote on 01/14/105:11 PM

Weakly type languages can run into interesting problems like this. In Adobe's ColdFusion, the first order of evaluation is to see if the values might be a date/time. In this situation, it will treat them as such and consider them equal. The key to remember is to go with the string compare functions instead.

Write your comment

(it will not be displayed)