In the Live Docs - ColdFusion Developer's Guide, under the subject "Using
scopes", you will find the following quote: "Because ColdFusion must search for
variables when you do not specify the scope, you can improve performance by
specifying the scope for all variables." I have always taken this for gospel.
However, I was debugging an application that makes me question that statement.
It seems that one of our developers named a query "request." (<cfquery
name="request">...</cfquery>) This made for some very confusing code such as
<cfoutput>#request.recordID#</cfoutput>. In this case "request.recordID" is
really "variables.request.recordID." This got me thinking about how ColdFusion
evaluate variables. It is clear in this case that ColdFusion first checked the
"request" scope for "recordID" and not finding it there checked the other
scopes for "request.recordID" and found it in the "variables" scope.
I wrote the example below to demonstrate this issue. We are are CF 7 shop so I
have not tested this in CF 8.
<cfscript>
form.session = structNew();
form.session.type = "I live in the form scope.";
form.session.token = "bogus token";
</cfscript>
<cfoutput>
session.type = #session.type#<br>
session.cftoken = #session.cftoken#<br>
</cfoutput>
<hr>
<cfdump var="#form#" label="form scope"><br>
<cfdump var="#session#" label="session scope"><br>
<cfdump var="#variables#" label="variables scope">
I have the following questions:
1. Does the same thing happen in CF7 and CF8?
2. Why doesn't ColdFusion stop searching after checking the "session" scope, as
implied by the Live Docs statement.
Well in any case this is either a good argument for scope-prefixing all
variables (form.session.type, variables.request.recordID, etc) and/or an
argument for prohibiting the naming of variables with "reserved" scope names
(form, request, etc).
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
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:322713
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4