One of the useful features missing from ColdFusion is automatic getters and setters. This is a common practice used when writing Java Beans. Steven Ross wrote this utilizing onMissingMethod here

I have slightly tweaked this. You should know some limitations of onMissingMethod(). While external calls, say from a cfm page, will trigger the onMissingMethod calls, internal calls within the CFC will not utilize this behavior.

The behavior I wish to achieve is something like this:

  <cfset object = CreateObject("Component","baseObject") />
  <cfset object.val("Value") />
  <cfoutput>#object.val()#</cfoutput> <!--- Value --->

Inside the CFC is a different story, setting and getting is a little different

<cffunction name="GenericFunction">
  <!--- Set some variables --->
  <cfset setValue("var1") = "String1" />
  <cfset value = getValue("var1") /> <!--- Value now set to "String1" --->

Here’s the Helper functions to make this happen. You can read about advanced version of this very basic getter/setter code at Peter Bell’s Blog

    Author: Drew Wells

//Handles calls to functions that do not exist
//@MissingMethodName - Name of function being called
//@MissingMethodArguments - Arguments passed to non-existant function
function OnMissingMethod( ){
    if( StructKeyExists( arguments[2], "2" ) ){ //invalid, expected 1     argument

    } else if( StructKeyExists( arguments[2], "1" )  ){ //setter

        setValue( arguments[1], arguments[2][1] );

    } else { //getter

        return getValue( arguments[1] );

//Setter method
function setValue(){
    variables.instance[ arguments[1] ] = arguments[2];
//Getter method
function getValue(){
    if( StructKeyExists( variables.instance, arguments[1] ) ){
        return variables.instance[ arguments[1] ];