Skip to main content
Inspiring
July 13, 2007
Question

variable type

  • July 13, 2007
  • 2 replies
  • 295 views
I thought I saw the other day someone do something like

<cfif VariableType( myVariable ) EQ "struct"> do this...

where VariableType was some CFML function call. I was looking for something else at the time and didn't note the post.

I know I can do isStruct( myVariable ), isArray, isObject, etc. Is there a single function call that returns the type so I can just use a switch on the returned value?
    This topic has been closed for replies.

    2 replies

    Inspiring
    July 13, 2007
    > <cfif VariableType( myVariable ) EQ "struct"> do this...
    >
    > where VariableType was some CFML function call. I was looking for something
    > else at the time and didn't note the post.

    Well there's myVariable.getClass(), which kind of does what you want. It's
    Java, not CF, and will return the underlying Java class of the variable.

    However as Dan points out, you might get "inaccurate" results, as CF is
    fairly inaccurate with how it types variables in the first place.

    --
    Adam
    Inspiring
    July 13, 2007
    Probably not, because 1 could be a string or a number.