IsDefined dislikes the names of variables beginning with a number. Unless they are defined...

Hello

I detected a strange (for me) behavior of the IsDefined function. I have something like:

< cfif IsDefined ("url.vose") > < cfset = "value" unevariable > < / cfif >

< cfif IsDefined ("url.3d") > < cfset = "value" unevariable > < / cfif >

* If url.3d is set, all right. All work as expected.

* If url.3d is not defined, CF throws an error "Parameter 1 of function IsDefined, which is now url.3d, must be a syntactically valid variable name".

* If I use structKeyExists (url, "3d") instead of IsDefined("url,3d"), works as expected.

I have tried different combinations of variable names and extended (EP, url.5d, or form.3d) and the problem seems to be the number at the beginning of the name of the variable.

This is the expected behavior? I found it very strange that it works if the variable exists and only generates an error if not. Can it be considered a bug and should be reported?

TIA,

It doesn't matter if the language is CF or JavaScript or PHP-HTML - variable names are considered invalid if they do not begin with a letter or underscore.  You must friezer prefix a variable name with a number.

Also, I have heard many developers complain IsDefined().  Use rather StructKeyExists().

 blah blah blah 

 blah blah blah 

V/r,

^_^

Tags: ColdFusion

Similar Questions

Maybe you are looking for