Copy link to clipboard
Copied
I did some testing, and if I set some private CFC variables in the pseudo constructor on a bean, and then perform the respective setPropertyName( respectiveOptionalArgument ) inside the init() constructor, my setPropertyName() setters properly update the variables.my.propertyName value, and I've dumped this to verify that.
The only difference I've seen between adding CFPROPERTY and not, is that when you dump the Bean, there is a presence of a PROPERTIES sub-structure which has the values listed. This doesn't mean much to me, because my Beans that have instance data all inherit from a BaseBean CFC that gives them a getMemento() function (which dumps the variables.my instance data).
The only other thing I could think of that CFPROPERTY does is add an additional level of introspection, which has more value in development environments than production.
Any thoughts?
Copy link to clipboard
Copied
Aegis,
Could you post a minimal sample of your CFC code that can be tested?
-Carl
Copy link to clipboard
Copied
<cfcomponent>
<cfset variables.my = {} />
<cfset variables.my.name = '' />
<cffunction access="public" returntype="UserBean" name="init" output="false" hint="I return a User">
<cfargument required="false" type="string" name="name" hint="I am the user name" />
<cfset setName( arguments.name ) />
<cfreturn this />
</cffunction>
<cffunction access="private" returntype="boolean" name="init" output="false" hint="I set the name property">
<cfargument required="true" type="string" name="name" hint="I am the user name" />
<cfset variables.my.name = arguments.name />
<cfreturn true />
</cffunction>
</cfcomponent>
So if you call it like:
<cfset userObject = new UserBean( name="Aegis" ) /><cfdump var="#userObject#" />
You will see a dump of the object, and you can expand into the methods, but no properties are shown.
BUT if you add the following line immediately after the opening <cfcomponent> tag:
<cfproperty required="true" type="string" name="name" hint="I am the user Name" />
And then leave ALL the other code alone, dumping the UserObject results in an object with a PROPERTIES sub structure (that is inaccessible via syntax like UserObject.Properties...)
But in all my testing, modifying the UserObject changes the expected variables with or without properties, you just don't get that structure in the dump if you omit the <cfproperty> tag.
Copy link to clipboard
Copied
Is that just a typo in the post, or is your private method also called "init"? Should it be "SetName"? Seems like that could be a problem.
-Carl
Copy link to clipboard
Copied
It's a typo. I hand-coded the above, cutting down on my commenting and spacing in order to keep it minimal.