Question

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?

Was it helpful?

Solution 2

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

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top