This however works
<cfset test(1, 2) /> <cffunction name="test"> <cfoutput>#structCount(arguments)#</cfoutput> <cfdump var="#arguments#" /> <cfoutput>#structKeyExists(arguments, 'a3')#</cfoutput> </cffunction> OUTPUTS 2 struct 1 1 2 2 NO So it seems that when you use <cfargument your semi creating a structure of arguments that kind of half exist. Regards Dale Fraser http://dale.fraser.id.au http://cfmldocs.com http://learncf.com http://flexcf.com From: cfaussie@googlegroups.com [mailto:cfaussie@googlegroups.com] On Behalf Of Paul Kukiel Sent: Thursday, 5 January 2012 4:37 PM To: cfaussie@googlegroups.com Subject: Re: [cfaussie] Count the number of arguments passed into a function. I see what your saying now. Yeah seams wierd Paul On 5/01/2012 4:29 PM, Dale Fraser wrote: Take this simple example, there is clearly a bug in some of these CF functions <cfset test(1, 2) /> <cffunction name="test"> <cfargument name="a1" /> <cfargument name="a2" /> <cfargument name="a3" /> <cfargument name="a4" /> <cfoutput>#structCount(arguments)#</cfoutput> <cfdump var="#arguments#" /> <cfoutput>#structKeyExists(arguments, 'a3')#</cfoutput> </cffunction> OUTPUTS 4 struct A1 1 A2 2 A3 undefined A4 undefined NO So structCount counts it <cfdump can display it structKeyExists says it doesn't exist So it kind of half exists. Regards Dale Fraser http://dale.fraser.id.au http://cfmldocs.com http://learncf.com http://flexcf.com -----Original Message----- From: cfaussie@googlegroups.com [mailto:cfaussie@googlegroups.com] On Behalf Of Paul Kukiel Sent: Thursday, 5 January 2012 4:12 PM To: cfaussie@googlegroups.com Subject: Re: [cfaussie] Count the number of arguments passed into a function. It looks like you trying to access a property ( messageId ) of the instance with <cfif structKeyExists(messageCFC, "messageid")> presuming messageCFC is an instance of message ? Paul On 5/01/2012 3:54 PM, Gavin Baumanis wrote: > Hi there, > Let me explain what I am trying to do, > > the executive summary is that I want to count the number of arguments > passed into a function. > anyFunction(), might have 10 cfargument properties assigned to it. > But if I call; > anyFunction(arg1="1", arg2="2") > > Then I somehow want to be able to retrieve the value 2 (2 passed in > variables). > > Why, > Because I have a getObject method. > getObject is basically a cfquery and I filter the results of the > query, based on the arguments passed in. > so if I have; > getObject(myId = 1, yourId = 2); > > then it creates SQL that looks like; > select STUFF > from myTable > where 1=1 > and myid=1 > and yourid=1 > and...(add a number of arguments here....) > > If I do NOT pass in any arguments, then the SQL retrieves ALL rows > from the table. > But I want to do is; > If no arguments are passed in - create an empty object. > > (we have a getAllObjects function to retrieve all rows) > > maybe some code will help... > > I have two snippets of code; > One is a function in a CFC, the other is some code in a CFM template > that calls the function - pretty simple. > > myTestCFC.cfc: > <cffunction name="blah"> > <cfargument name="text" required="false" /> > <cfargument name="messageid" required="false" /> > <cfargument name="queryid" required="false" /> > <cfargument name="datasource" required="false" /> > > <cfset var local = {} /> > <cfset local.length = #structCount(arguments)#> > > <cfreturn local.length> > </cffunction> > > > test.cfm: > <cfset myReturnVal = myTestCFC.blah(text="gav", queryid=3)> <cfdump > var="#myReturnVal#"> <br /> <cfif structKeyExists(messageCFC, > "messageid")> > Yes > <cfelse> > No > </cfif> > > the output of this code is; > 4 > No > > The value 4 is because blah() has 4 arguments defined. > But structKeyExists, returns false... > > How can it not exist but be accounted for? > surely one of the values is wrong? > > If I change the code slightly to be; > <cfset local.length = #structKeyList(arguments)#> instead of; <cfset > local.length = #structCount(arguments)#> > > Then all four arguments defined in the "stub" of the function are > listed. > > So is one of the values being returned a bug? > > and lastly, > How do I go about "counting" actual passed in aerguments? > (I could write another function that loops through > structKeyLists(arguments), then do a structKeyExists[i] and increment > a counter and do my own accounting.... > but it just "seems" like there should be a nicer way to do it... > > As always - Thanks for any thoughts! > > Gavin. > -- You received this message because you are subscribed to the Google Groups "cfaussie" group. To post to this group, send email to <mailto:cfaussie@googlegroups.com> cfaussie@googlegroups.com. To unsubscribe from this group, send email to <mailto:cfaussie+unsubscr...@googlegroups.com> cfaussie+unsubscr...@googlegroups.com. For more options, visit this group at <http://groups.google.com/group/cfaussie?hl=en> http://groups.google.com/group/cfaussie?hl=en. -- You received this message because you are subscribed to the Google Groups "cfaussie" group. To post to this group, send email to cfaussie@googlegroups.com. To unsubscribe from this group, send email to cfaussie+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/cfaussie?hl=en. -- You received this message because you are subscribed to the Google Groups "cfaussie" group. To post to this group, send email to cfaussie@googlegroups.com. To unsubscribe from this group, send email to cfaussie+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/cfaussie?hl=en. -- You received this message because you are subscribed to the Google Groups "cfaussie" group. To post to this group, send email to cfaussie@googlegroups.com. To unsubscribe from this group, send email to cfaussie+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/cfaussie?hl=en.