Skip to main content
WolfShade
Legend
December 7, 2016
Question

Variable "varName" undefined when trying to call a function

  • December 7, 2016
  • 2 replies
  • 702 views

Hello, all,

I was just shown that an application written by someone else over ten years ago is working fine under CF9 and CF10; but it's breaking in CF11.

I have something like:

<cfinclude template="../myComponent.cfc" />

Now, in myComponent.cfc, I have a function:

<cffunction name="getThisAttribute" returntype="string" output="no">

  <cfargument name="part1" /><cfargument name="part2" />

  ...

  <cfreturn thisValue />

</cffunction>

Under CF11, in the first page (again, this works in CF9 and CF10), if I do the following:

<cfset thisVar = getThisAttribute(part1,'part2') />

I get "getThisAttribute undefined".  Am I going to have to completely re-write how all this works if we switch to CF11???

V/r,

^_^

    This topic has been closed for replies.

    2 replies

    EddieLotter
    Inspiring
    December 7, 2016

    That's definitely not how CFC's are supposed to be used.

    I suspect the quickest solution would be to rename the CFC file to a CFM file and do a search and replace in all scripts that include the file.

    Cheers

    Eddie

    WolfShade
    WolfShadeAuthor
    Legend
    December 9, 2016

    That's definitely not how CFC's are supposed to be used.

    Oh, I know.  I inherited this code, it was written over ten years ago (round about CF MX6 or MX7, methinks), and I'm personally hoping that it is so old, outdated, and just plain vulnerable that the client will agree to just deleting the whole thing, possibly writing another from scratch.

    V/r,

    ^_^

    BKBK
    Community Expert
    Community Expert
    December 7, 2016

    Not quite kosher code, but it should work. What about:

    <cfset thisVar = getThisAttribute('part1','part2') />

    or

    <cfset thisVar = getThisAttribute(1,2) />

    WolfShade
    WolfShadeAuthor
    Legend
    December 7, 2016

    Thanks for the suggestion, BKBK​, but getThisAttribute is a function in the CFC that is CFINCLUDEed prior to the CFSET; but CF is convinced that getThisAttribute is not defined.  It's not the arguments that are preventing anything - it just doesn't exist.

    I thought perhaps that it might be because the CFC is CFINCLUDE, not a component that is mapped and accessed via <cfset thisVar = new components.getThisAttribute(part1,'part2') />, but that is weird since it works in CF9/10.

    V/r,

    ^_^

    Legend
    December 7, 2016

    To me this looks like a bug in CF9 & 10 that you unintentionally exploited. The getThisAttribute appears to be defined as a function of the myComponent and nowhere are you reverencing a myComponent instance. Now if your first module was a cfc and you used the extends="myComponent" parameter, then your cfset call should work -- although on occasion I have had to explicitly state this.getThisAttributes(...) for unknown reasons.