> > > Are variables passed by reference or by value in CF UDFs?
> >
> > Queries, structures, and variables created using CFOBJECT
> > are passed by reference. Other variables are passed by value.
> > This is true whether passing them to UDFs or custom tags or
> > whatever, as far as I can tell.
>
> While I can understand this in a UDF, I just can't understand
> why this is true for a custom tag. I just tried it out and an
> array is passed by value to a custom tag. A structure is passed
> by reference. This totally breaks the paradigm of custom tags
> being "totally independent processes".
I don't really see a significant difference between UDFs and custom tags in
terms of how they relate as callable modules of code - functions - to the
larger programs of which they're a part. I'd never thought of custom tags as
being "totally independent processes" - after all, the fact that they are
called makes them dependent on a caller!
Before CF 5 came out, I always thought of custom tags as largely analogous
to user-defined functions, and in fact, would call them that in classes.
They're modules of code with clearly defined entry points (even if the exit
points aren't quite so clearly defined), and they have their own separate,
internal scope. Given that, I'd expect that if objects are passed by
reference in general, they should also be passed by reference when being
passed to a custom tag.
Of course, in the long run, it really doesn't matter, as long as we know
what behavior to expect. However, there are useful benefits to passing
structures by reference to custom tags. For example, let's say we wanted to
filter input. Ideally, we could use an external component for that, since
CF's string handling doesn't seem to be as fast as we'd like it to be, but
the CFX interface doesn't support that, as far as I can tell. We could,
however, build a custom tag that accepts one or more structures as
attributes, and makes changes to those structures' contents.
Dave Watts, CTO, Fig Leaf Software
http://www.figleaf.com/
voice: (202) 797-5496
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists