Skip to main content
Ben Nadel at Scotch On The Rocks (SOTR) 2011 (Edinburgh) with: Hugo Sombreireiro
Ben Nadel at Scotch On The Rocks (SOTR) 2011 (Edinburgh) with: Hugo Sombreireiro

ColdFusion Query Argument Reference Can Be Confusing

By
Published in

I was experimenting with a QueryAppend() function when I came across an interesting caveat to query variables. In ColdFusion, queries are passed around by reference. That is, if you pass a query to a method, such as QueryAddRow(), no query is returned because the original query object is updated by reference; however, this does not always seem to be the case. In my experimentation, I found that QueryAddRow() did in fact update the original query:

<cfset QueryAddRow( ARGUMENTS.QueryOne ) />

... but, changing the pointer of the query did NOT change the original reference:

<cfset ARGUMENTS.QueryOne = 3 />

This one leaves the original query alone and only affects the local variable, ARGUMENTS.QueryOne. I am sure this has to due with when the variable value is dereferenced or evaluated, but it seems to be a bit confusing.

Want to use code from this post? Check out the license.

Reader Comments

I believe in love. I believe in compassion. I believe in human rights. I believe that we can afford to give more of these gifts to the world around us because it costs us nothing to be decent and kind and understanding. And, I want you to know that when you land on this site, you are accepted for who you are, no matter how you identify, what truths you live, or whatever kind of goofy shit makes you feel alive! Rock on with your bad self!
Ben Nadel