Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ColdFusion structkey starting with number

Why does this fail:

<CFIF isdefined("URL.3dfile")>...</CFIF>

with following message:

Parameter 1 of function IsDefined, which is now URL.3dfile, must be a syntactically valid variable name.

and this won't:

<CFIF structkeyexists(URL,"3dfile")>...</CFIF>

Is the way it get's parsed not much the same? And .. are variables starting with numbers invalid or aren't they?

like image 868
Seybsen Avatar asked Jan 27 '26 18:01

Seybsen


1 Answers

Seybsen - variables names should not begin with a number. This is likely a legacy of older non-java version of CF Where a variable was not part of an object.

However, in the java world everything IS an object. This leads to a syntactical nuance. If you are using variable names in dotted notation your var name will likely throw an error. But use it in other ways and it will succeed.

So this sort of syntax works url['33foo']

But setting a variable name directly - 33foo = true - will not work.

Here's a post with a full explanation.

http://www.coldfusionmuse.com/index.cfm/2005/9/8/isdefined%20vs%20structkeyexists

like image 197
Mark A Kruger Avatar answered Jan 30 '26 19:01

Mark A Kruger