3

I'm working on an application built on Railo4 and am running into an interesting issue. I'm not doing anything new here as far as ColdFusion code goes. simply taking some strings, concatenating where needed, and returning a string.

<cffunction name="customBuildURL" access="public" returntype="string">

    <cfargument name="subsystem" type="string" required="true" />
    <cfargument name="section" type="string" required="true" />
    <cfargument name="item" type="string" required="true" />
    <cfargument name="args" type="string" required="true" />

    <cfset var url = "index.cfm?action=" & ARGUMENTS.subsystem & ":" & ARGUMENTS.section />

    <cfif Ucase(ARGUMENTS.item) NEQ "DEFAULT" >
        <cfset url &= "." & ARGUMENTS.item />
    </cfif>

    <cfif ARGUMENTS.args NEQ "" >
        <cfset url &= ARGUMENTS.args />
    </cfif>

    <cfreturn url />

</cffunction>

However, I'm getting two unusual errors.

1) The first is: Can't cast Complex Object Type Struct to String and is being reported for the following two lines:

<cfset url &= "." & ARGUMENTS.item />

<cfset url &= ARGUMENTS.args />

2) The second is the function customBuildURL has an invalid return value , can't cast Object type [url] to a value of type [string] upon return of the url variable.

As you can see, I'm not doing anything elaborate here. Just setting some strings, concatenating them and then returning it. I don't see where an 'Object' is being created and being cast as a string. I double checked the use of the &= operator and that doesn't appear to be the issue because if I do a url = url & "." & ARGUMENTS.item the same error is reported.

Any ideas?

Anil
  • 2,539
  • 6
  • 33
  • 42
  • 1
    What happens if you use a variable other than url? I'm assuming it's still pulling in the url structure – Matt Busche Jul 20 '13 at 03:14
  • That fixed it! I wish you would have posted this as an answer, I could have given you credit for it. I stared at this for hours, but didn't realize I made a newb mistake. URL scope was conflicting with my variable! D'OH! In any case, changed the `url` variable to `actionURL` and everything works now! Thanks Matt! Sometimes an extra set of eyes is all you need when you've stared at it too long. – Anil Jul 20 '13 at 03:18
  • No problem. I posted this as an answer. – Matt Busche Jul 20 '13 at 03:33

2 Answers2

4

Sly,

Railo does not allow you to use ANY scope as a variable inside functions. This is an intentional incompatibility, since Coldfusion does allow that. But after doing that, you will not be able to access the URL scope anymore. That's why we don't allow that. Just call the variable sUrl for instance.

HTH

Gert Franz Railo ltd.

Gert
  • 51
  • 2
  • 1
    Just an aside: Gert is the CEO of Railo (http://www.getrailo.com/index.cfm/about-us/railo-team/gert-franz/) – James A Mohler Jul 21 '13 at 03:54
  • Thanks for the clarification Gert! I appreciate the follow-up. This was a stupid mistake on my part. In all my days of CF programming I've ALWAYS tried to stay away from using variable names that are the same as scope variables, but in this one instance, I was quickly prototyping something and did what I shouldn't have done. In any case, thanks for the clarification. You're assistance has been very helpful, especially for the organization I belong to. ;) – Anil Jul 21 '13 at 17:46
3

Url is a reserved word in ColdFusion, so even though you're var-ing it in the function it's still picking up the actual structure of url variables.

Here's a complete list of reserved words in ColdFusion

Leigh
  • 28,765
  • 10
  • 55
  • 103
Matt Busche
  • 14,216
  • 5
  • 36
  • 61