Tonight I played around with onMissingMethod, a cool new feature in ColdFusion 8. See Ben Nadel's entry on it for more detail. I knew that the method took two arguments - the name of the method invoked and a struct of the arguments that was passed.

What I didn't realize and was surprised by - you can't rename these arguments. So consider this:

<cffunction name="onMissingMethod" access="public" returnType="any" output="false"> <cfargument name="method" type="string" required="true"> <cfargument name="args" type="struct" required="true">

While the method itself will run, the arguments above will not actually be used. You must name them as Ben describe's in his entry:

<cffunction name="onMissingMethod" access="public" returnType="any" output="false"> <cfargument name="missingMethodName" type="string" required="true"> <cfargument name="missingMethodArguments" type="struct" required="true">

As a side note - for the life of me I couldn't find any mention of onMissingMethod in the docs - neither the Developer's Guide nor the Reference. Can anyone else find it?

This is the code I'm using in a generic bean:

<cfcomponent name="Core Bean" output="false">

<cffunction name="onMissingMethod" access="public" returnType="any" output="false"> <cfargument name="missingMethodName" type="string" required="true"> <cfargument name="missingMethodArguments" type="struct" required="true"> <cfset var key = "">

<cfif find("get", arguments.missingMethodName) is 1> <cfset key = replaceNoCase(arguments.missingMethodName,"get","")> <cfif structKeyExists(variables, key)> <cfreturn variables[key]> </cfif> </cfif>

<cfif find("set", arguments.missingMethodName) is 1> <cfset key = replaceNoCase(arguments.missingMethodName,"set","")> <cfif structKeyExists(arguments.missingMethodArguments, key)> <cfset variables[key] = arguments.missingMethodArguments[key]> </cfif> </cfif>

</cffunction>

</cfcomponent>

This let's me define a simple bean like so:

<cfcomponent output="false" extends="bean">

<cfset variables.id = ""> <cfset variables.username = ""> <cfset variables.password = ""> <cfset variables.name = ""> <cfset variables.email = "">

</cfcomponent>