Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Backward compatibility between ColdFusion 9 and ColdFusion 7 with regards to CFScript?

Tags:

coldfusion

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.

like image 597
ryan Avatar asked Jan 20 '23 04:01

ryan


2 Answers

Yes, in CF7 you need to use ColdFusion's native comparison operators, in your case neq.

Replace

  • == with eq
  • != with neq
  • > with gt
  • < with lt
  • >= with gte
  • <= with lte
  • % with mod

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 a var local = StructNew(); at the top of their CF7 functions, which will also work in CF > 7.
like image 104
Tomalak Avatar answered Jan 21 '23 17:01

Tomalak


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...

like image 29
sebduggan Avatar answered Jan 21 '23 18:01

sebduggan