> It's not a question of circumvention, just of understanding how things
> operate under the covers. If a statement is made in the docs that "any
> variables local to a UDF are destroyed when the UDF is exited", where
> does it leave things like the query in my example. Either it is not
> destroyed, and a reference to the query is passed or it is destroyed
> and a copy (ala the duplicate() function) is passed. Dave holds by the
> former.

Well, the answer to that question depends on how you define
"variable". From the perspective of the programmer, the variable is
destroyed - I can't reference it any more after the function has
finished. But under the covers, again, there is more than just a
"variable". There's an object, and a reference to that object. We
generally think of the references as if they were the variables,
because that makes sense and is usually the most convenient way to
think of things. If I'm trying to explain the scope of variables
created within a function to an inexperienced programmer, I'm going to
hold off talking about passing by value vs passing by reference. But
really, it's the objects that matter.

And it's clear that queries and structures are passed by reference.
You can see this clearly by assigning a query to a new name, and then
changing the contents using either the original or the new name -
you'll see the contents have changed for "both" (and of course,
there's really only one query object in memory). To see this at work
in the context of a function, write a function that creates a local
query, copies that to a persistent variable (session, application,
server) and returns the local query. Then, outside the function,
change either the persistent query or the returned query, and you'll
see that one changes the other, because again they actually point to
the same object on the heap.

Dave Watts, CTO, Fig Leaf Software
http://www.figleaf.com/
http://training.figleaf.com/

Fig Leaf Software is a Veteran-Owned Small Business (VOSB) on
GSA Schedule, and provides the highest caliber vendor-authorized
instruction at our training centers, online, or onsite.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Want to reach the ColdFusion community with something they want? Let them know 
on the House of Fusion mailing lists
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:331519
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm

Reply via email to