Straight from the online documentation:

--------------------------
Passing arguments 

ColdFusion passes arrays and simple data types including integers, strings,
and time and date values into the function by value. It passes queries and
structures into the function by reference. As a result, if you change the
value of a query or structure argument variable in the function, it changes
the value of the variable that the calling page used in calling the
function. However, if you change the value of an array or string argument
variable in the function, it does not change the value of the string
variable in the calling page. 
--------------------------

I shoulda looked it up sooner.  Sorry...  <grins>

Shawn Grover

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Sent: Monday, September 10, 2001 1:35 PM
To: CF-Talk
Subject: RE: Passing variables in UDF


I was wrong in saying that an array was passed by reference. I just tested 
it out and it is passed by value. I was assuming based on the normal array 
function results that it would be. I hate when things are not 'standard'.

Causes an error
<CFSCRIPT>
         function test(aVar)
         {
                 aVar[1] = "name";
         }
         aVar=ArrayNew(1);
         test(aVar);
         WriteOutPut(aVar[1]);
</CFSCRIPT>

works
<CFSCRIPT>
         function test(aVar)
         {
                 aVar[1] = "name";
                 return aVar;
         }
         aVar=ArrayNew(1);
         aVar=test(aVar);
         WriteOutPut(aVar[1]);
</CFSCRIPT>


At 03:21 PM 9/10/01, you wrote:
>If the var is simple or array, then it is by value. If you pass in a
>struct or a query, then it is by ref.
>
>=======================================================================
>Raymond Camden, Principal Spectra Compliance Engineer for Macromedia
>
>Email    : [EMAIL PROTECTED]
>Yahoo IM : morpheus
>
>"My ally is the Force, and a powerful ally it is." - Yoda
>
> > -----Original Message-----
> > From: Carlisle, Eric [mailto:[EMAIL PROTECTED]]
> > Sent: Monday, September 10, 2001 1:24 PM
> > To: CF-Talk
> > Subject: Passing variables in UDF
> >
> >
> > Are variables passed by reference or by value in CF UDFs?
> >
> >       Thanks,
> >
> >
>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at 
http://www.fusionauthority.com/bkinfo.cfm
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to