Search code examples
coldfusioncoldfusion-9cfml

Inconsistent behaviour in script and tag based approach in CF


I wrote the below code block with cfset,

<cfset variables.test = 3>
<cfset variables.check = variables.test == 5>

<cfdump var="#variables#">

but this code block generated the error, "ColdFusion was looking at the following text: = "

While I wrote the above block within cfscript it provide me the correct reasult. Here is the cfscript code block.

<cfscript>
  variables.test = 3;
  variables.check = variables.test == 5;

  writeDump(variables);
</cfscript>

Here is the output of the cfscript code block.

enter image description here

I am not sure why script and tag based approach is behaving differently in this case. Please suggest, why the tag based approach is generating an error.

Note: I have tested this in CF9.


Solution

  • You can't use "==" as a decision operator with tags. Use "EQ".

    Try...

    <cfset variables.test = 3>
    <cfset variables.check = variables.test EQ 5>
    
    <cfdump var="#variables#">

    Doc reference: "The CFScript language: Expressions and operators"