Last updated on
Sep 5, 2022
|
Also applies to ColdFusion
This feature lets you set your CFC property as a simple variable assignment, without specifying the setters. That is, you can set the property by setting the property field rather than by invoking the setter method for the property.
Similarly, the property value can be accessed by referencing the property name, rather than by invoking the getter for the property.
In ColdFusion, you can set invokeImplicitAccessor in a CFC, as well as in Application.cfc.
Example
empname.cfm
<cfscript> name = new empname(); name.first="Paul"; name.last="Scholes"; writeOutput("First: #name.first#<br>"); writeOutput("Last: #name.last#<br>"); </cfscript>
empname.cfc
component invokeImplicitAccessor = "true" { property string first; property string last; function setFirst(first){ writeOutput("#getFunctionCalledName()# called<br>"); variables.first = arguments.first; } function setLast(last){ writeOutput("#getFunctionCalledName()# called<br>"); variables.last = arguments.last; } function getFirst(){ writeOutput("#getFunctionCalledName()# called<br>"); return variables.first; } function getLast(){ writeOutput("#getFunctionCalledName()# called<br>"); return variables.last; } }