Quantcast
Channel: Adobe Community: Message List - ColdFusion
Viewing all articles
Browse latest Browse all 21760

Re: What's the point in using CFPROPERTY for my Beans?

$
0
0

<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.


Viewing all articles
Browse latest Browse all 21760

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>