Backward compatibility between ColdFusion 9 and ColdFusion 7 with regards to CFScript?
I am a complete ColdFusion newbie so apologies in advance for my upcoming ignorance.
We are having an issue with an existing CFScript. The problematic script contains the following line:
...
if (fields.length() != 0) {
开发者_开发问答 // do something
}
...
The script runs successfully in ColdFusion 9, but we see the following message when trying to run the script in ColdFusion 7:
...
Invalid token '!' found on line...
...
I'm guessing that ColdFusion 7 does not like the '!=' operator, am I correct?
If so, are there any other backward compatibility issues with CFScript that could cause us to trip up? I've been searching for resources but there doesn't seem to be anything definitive.
Thanks.
Yes, in CF7 you need to use ColdFusion's native comparison operators, in your case neq
.
Replace
==
witheq
!=
withneq
>
withgt
<
withlt
>=
withgte
<=
withlte
%
withmod
and you're good to go. These operators are upward-compatible, CF9 will understand them.
Other than that,
- you need to group all your local variables (those declared with
var
) at the top of a function in ColdFusion 7. This restriction has gone away in later editions of ColdFusion, but scripts written that way will of course continue to run. - there is an automatic
local
scope as of CF9. This scope was not available in CF7 and CF8, but by convention people added avar local = StructNew();
at the top of their CF7 functions, which will also work in CF > 7.
You're right - the Javascript-like operators (!=, ==, ||, etc.) were only introduced in ColdFusion 9, along with a whole lot more scripting support.
This mostly relates to full script support for CFCs, but there are probably plenty of other other gotchas out there...
精彩评论