Can I pass a simple value by reference in ColdFusion?

By default, ColdFusion passes simple functions (such as numeric, string, and GUIDs) by value in the function. I would like to pass a simple type by reference.

Currently, I am transferring a simple value to a structure (they are passed by reference). This solves my problem, but it is very ugly:

<!--- TheFunctionName---->
<cffunction name="TheFunctionName">
     <cfargument name="OutVariable" type="struct">
     <cfset OutVariable.ID = 5>
</cffunction>

<cfset OutVariable=StructNew()>
<cfset TheFunctionName(OutVariable)>

<!--- I want this to output 5--->
<cfoutput>#OutVariable.ID#</cfoutput>

I would prefer something like this:

<!--- TheFunctionName---->
<cffunction name="TheFunctionName">
     <cfargument name="OutVariable" passbyref="true">
     <cfset OutVariable = 5>
</cffunction>

<cfset TheFunctionName(OutVariable)>

<!--- I want this to output 5--->
<cfoutput>#OutVariable#</cfoutput>
+3
source share
3 answers

AFAIK, there is no way to pass simple values ​​by reference in ColdFusion. The only workaround I can think of is the one you are already using.

. , "", :

<cfset SomeVar = TheFunctionName(SomeVar)>

, , , CFC, CFC. , .

+8

, , , . , "" "", . .

, , . , , , .

<cffunction name="TheFunctionName">
     <cfset Request.StrVar = "inside function<br />" />
</cffunction>

<cfscript>
    Request.StrVar = "outside function<br />";
    WriteOutput(Request.StrVar);
    TheFunctionName();
    WriteOutput(Request.StrVar);
</cfscript>

ColdFusion

- , , , <cfparam> ; IsDefined().

+1

:

  • CFC
  • , <cfinvoke>

You could specify the <cfinvoke> parameter "returnvariable" and then output this variable as you like.

<cfinvoke component="this" method="TheFunctionName" returnvariable="blah">
     <cfinvokeargument name="data" value="whatever" type="string">

     <cfreturn data>
</cfinvoke>

<cfdump var="#blah#">

If you write everything in cfscript, I would say that I said SurroundedByFish.

+1
source

Source: https://habr.com/ru/post/1712903/


All Articles