ColdFusion 10 added implicit accessors and in this post I'll cover how to turn them on and use them.
Turning on implicit accessors is achieved via a straightforward setting in application.cfc:
component {
this.name = "implicitFun";
this.invokeImplicitAccessor = true;
}
Once on this means we can now access a getter and setter function of an object/cfc using the same syntax as if it where a struct. Let's look at a simple component called user.cfc:
component accessors="true" {
property firstname;
property lastname;
function getFirstname() {
return UCase( variables.firstname );
}
function getName() {
return variables.firstname & " " & variables.lastname;
}
}
Now let's see what happens when we make an object and start interacting with it:
As you can see from the code above when you call the implicit accessor on an object it calls the getter or setter function but within a cfc calling the variables scope directly calls the variable and not the getter or setter function.