ColdFusion Developers - Spot the Mistake

Take a look at this code:

view plain print about
1<cffunction name="getFilterString" output="false" access="public" returntype="string" hint="I return the search filter list">
2 <cfargument name="avoid" type="string" default="" />
3 <cfset var x = "" />
4 <cfset var dynHasFunct = "" />
5 <cfset var dynGetFunc = "" />
6 <cfset var rtnVal = "" />
7
8 <cfloop collection="#variables.instance#" item="x">
9 <cfset dynHasFunc = variables["has#x#"] />
10 <cfset dynGetFunc = variables["get#x#"] />
11 <cfif NOT listFind( arguments.avoid, x) AND dynHasFunc() >
12 <cfset listAppend( rtnVal, "#x#=#dynGetFunc()#", "&") />
13 </cfif>
14 </cfloop>
15 <cfreturn rtnVal />
16 </cffunction>

I just spent 15 minutes tracing all this code out trying to find out why nothing was returned. The intent of the code is to build a string containing values present in the object. So if a user searches by Category, UserID etc, the search string is maintained.

Warning, the error is simpler than you might think. Don't over think it.

There are no comments for this entry.

Add Comment Subscribe to Comments