4

Here I come up with question about Reserved words. As per my knowledge a keyword can not be a variable.

I've faced a issue about passing reserved word string as a argument in both script based code but not face any error while wrote a same code in tag based. My question here is , I passed argument name as For.If it's reserved word mean we could not able to use both tag & script based right. How the reserved word accept in tag based code ? Correct me if I'm wrong understood anything.

FYR : I've attached my code and successful resule for tag based code and error for script based code.

<cfset testCall = callFunc( a=10,For=20)>
Out put :#testCall#

<cfscript>
    testCall = callFunc( a=10,For=20);
    writeDump(testCall);

</cfscript>

<cffunction name="callFunc" access="public" returntype="Any">
    <cfargument name="a" required="true">
    <cfargument name="For" required="true">
    <cfreturn ARGUMENTS.a * ARGUMENTS.For>
</cffunction>

Output : 200 ( This is an tag based output )

The below issue is script based code,

enter image description here

Could any one know why it's was happened ? Or correct me if I'm wrong understood. Thanks in advance !

James A Mohler
  • 11,060
  • 15
  • 46
  • 72
Kannan.P
  • 1,263
  • 7
  • 14
  • 1. What version of ColdFusion? 2. I suspect this is an undocumented anti-feature. For all we know, `callFunc` is how the ColdFusion internals do something 3. Consider putting in a bug report to https://tracker.adobe.com – James A Mohler May 09 '19 at 14:47
  • I'm using cf 11. – Kannan.P May 09 '19 at 15:15
  • 1
    The only thing I can think of is that `for` does not mean anything in the tag language. There is not a `for` loop in tags (at least not in that syntax), it is only used in script. – Miguel-F May 09 '19 at 17:04
  • 4
    I wouldn't try using `for` as a variable name in *any* language ;-) It's just too common a reserved words There may not be a ` tag, but it's definitely used in cfscript. My guess is you're running afoul of some internal cfscript parser that sees `for` as a command in that context. – SOS May 09 '19 at 18:03
  • Yes @Miguel-F & Ageax. That's why I mentioned it as "A key word can not be a variable" This is an basic rule of programming. So that I'm asking about how we can use it in tag itself. Currently I switch cf11 to 18 so I changed tag to script for my code. Client used 'For' as a argument ( Like he used Final, etc...). But while converting to script it's not allowed. So while work for improvement we can focus on only reduce code / load time etc.. But we can't focus on arguments name. Right.? – Kannan.P May 09 '19 at 18:09
  • 1
    (cont'd) Notice there's a separate section on [keywords in script syntax](https://helpx.adobe.com/coldfusion/developing-applications/the-cfml-programming-language/elements-of-cfml/reserved-words-in-coldfusion.html)? If you want to convert the CFML code to cfscript, unfortunately you may have to change some variable names. – SOS May 09 '19 at 18:36
  • 3
    (Edit) They used "final" as a variable name? Yipes! CFML and CFScript are kind of two different "languages" (for lack of a better word). While you might hope any CFML code would work the exact same way in cfscript - you can't depend on that. CFScript has syntax elements that CFML doesn't. Therefore some things will work or be reserved words in one, but not in the other. – SOS May 09 '19 at 22:32
  • I would have to echo Ageax in that it's never a good idea to use common reserved words. And what's worse is when it doesn't throw a hard error like this but has a silent error that can be an extreme pain to troubleshoot, if it's even noticed. – Shawn May 13 '19 at 17:14
  • Yes @Shawn. That is what I felt before find the bug.This kind of bug can be found by very deep eye on that part :) . But interesting to me. – Kannan.P May 13 '19 at 18:15
  • It's already hard enough to name things, but throw in Reserved Words (or words that are likely to _become_ Reserved Words), and it's enough to make you pull your hair out. :-) – Shawn May 13 '19 at 18:20
  • It's *not* a bug. The syntax of the two are different, so of course the reserved words are different too - as noted in Adobe's own docs. IMO the only thing that might be considered a bug is the poor error handling ;-) – SOS May 23 '19 at 20:14

0 Answers0