What Does cfargument Really Do?
It seems obvious that cfargument defines the arguments for your udfs/methods. It is easy, however, to have assumptions about what it does that aren't correct.
Primarily, cfargument defines that arguments that you expect for your function and the order in which you expect them. This helps document your code.
It also acts like cfparam in that it defines a data-type for an argument (throwing an error if the argument isn't of that type) and either making the argument required or providing a default (technically you can do both or neither in cfargument, but that doesn't really make sense.
It also assigns names to arguments that are passed in ordinally (that is, arguments passed in by order but without a specified name). This allows you to pass in arguments either by name or by order.
What cfargument doesn't do, however, is just as important. It doesn't restrict the arguments that come into your function to those specified by cfargument tags.
So, any arguments that are passed in by name will still exist in the arguments structure of the function. This has both drawbacks and advantages. The drawbacks primarily have to do with security. If you use argumentCollection to pass in a Form structure then any form field will be sent in as an argument.
Among the advantages are the ability to pass in argument names that are not known before hand. It also means that you can have named arguments without any cfargument tags at all (though you lose out on important documentation if you do).
Ideally, I would like to be able to check what arguments have been defined by cfargument from within the tag (so that I could programmatically delete other arguments if I wanted without changing that code every time I added an argument). I suspect it can be done, I just don't know how.
Anyone?
I want to know if someone passed argument.foo
then you should simply use structKeyExists on the argument. Shoot, you can do this WITH using the cfargument tag, just don't use a default
Sorry, I didn't explain myself well. What I want is just a list (or structure or whatever) of the arguments that have been defined with cfargument, regardless of whether or not they are actually passed in to the method.
The idea being, that I could then use StructDelete() on any incoming named arguments that weren't documented in cfargument.
I don't know if I actually have a real-world need for this, but it seems like it could be handy.
I know this can be done from outside the method. I just don't know how to do it from within the method.
Specifically, to get the data you're looking for:
That certainly does what I said I want - and from within the function. I don't like that it requires the code inside of a function to know the name of the function - but I doubt that any better solution is possible.
That is certainly better than anything that I have come up with.
Thanks!
I don't remember anyone mentioning that about cfargument, but Ben Nadel mentioned that about cfparam.
http://bennadel.com/index.cfm?dax=blog:594.view
I have noticed that I use type="string" a lot where I want type="numeric" and then I have logic in the method to delete the argument or set it to a default numeric value if it isn't a valid number. Always seems like there should be an easier way.