Implicit Constructors
Along with the magic functions and the ability to add accessors to your properties, Railo 4.0 also gives you the ability to magically create and initialise components without having to add the init() method!
A simple example is for a component with two properties:
<cfcomponent accessors="TRUE"> <cfproperty name="firstname" type="string" setter="true"/> <cfproperty name="lastname" type="string" setter="true"/> </cfcomponent>
Now you are able to create the component as usual:
cfc = new cfcs.Constr_1(); dump(var=cfc, label="Normal Instantiation of a CFC");
But of course, you would still need to call the setFirstName() and setLastName() accessor functions. In Railo 4 we give you the ability to set the properties when you create the compenent easily via:
Named Arguments:
cfc = new cfcs.Constr_1(firstname:"Susi",lastName:"Sorglos"); dump(var=cfc, label="setting properties via the constructor");
or by the argumentCollection:
cfc = new cfcs.Constr_1(argumentCollection:{firstname:"Susi",lastName:"Sorglos"});
dump(var=cfc, label="Properties set via explicit argumentCollection");