Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ColdFusion error using IsDefined(): parameter must be a syntactically valid variable name

Tags:

coldfusion

In ColdFusion, when I call IsDefined("root.L1[1].L2"), I am getting the following error:

Parameter 1 of function IsDefined, which is now root.L1[1].L2, must be a syntactically valid variable name.

This is a valid variable name, so what gives?

Here is my simplified test code:

<cfscript>
  root = StructNew();
  root.L1 = ArrayNew(1);
  root.L1[1] = StructNew();
  root.L1[1].L2 = "foo";

  WriteOutput("root.L1[1].L2 is: #root.L1[1].L2#<br/>"); //no exception

  if(IsDefined("root.L1[1].L2")) //exception!
    WriteOutput("It is defined!");
  else
    WriteOutput("It is not defined!");
</cfscript>
like image 481
Jenni Avatar asked Dec 13 '22 20:12

Jenni


1 Answers

Try

StructKeyExists(root.L1[1],"L2")

instead of isDefined()

I vaguely recall there being issues with complex variables with isdefined(), but I can't recall the version.

like image 156
Stephen Moretti Avatar answered Jun 02 '23 13:06

Stephen Moretti