tracker issue : CF-3352745

select a category, or use search below
(searches all categories and all time range)
Title:

properties with default values not accessible outside init function

| View in Tracker

Status/Resolution/Reason: Closed/Fixed/

Reporter/Name(from Bugbase): Tom Van Schoor / Tom Van Schoor (Tom VS)

Created: 10/25/2012

Components: CFComponent

Versions: 10.0

Failure Type:

Found In Build/Fixed In Build: Final / CF11 Update5,CF10 Update16

Priority/Frequency: Normal / Some users will encounter

Locale/System: English / Windows 7 64-bit

Vote Count: 2

Listed in the version 11.0.05.293506 Issues Fixed doc
Problem Description: When creating a component with accessors="true" and a property with a default value the variables struct does not contain the property in any method withing the component unless you set them explicitly in the init function.

Steps to Reproduce:
MyTest.cfc:
component accessors="true" {
	
	property name="privateVarOne" default="privateVarOne default";
	
	function init() {
		return this;
	}
	
	public void function newMethod() {
		var myVar = variables.privateVarOne;
		writedump(var="success");
	}
}

test.cfm:
<cfset test = new MyTest() />
<cfset test.newMethod() />

Actual Result:
Element PRIVATEVARONE is undefined in VARIABLES.

Expected Result:
success

Any Workarounds:
With a dump in-between it suddenly magically works:
<cfset test = new MyTest() />
<cfdump var="#test#" format="html">
<cfset test.newMethod() />


Explicit setting of variables.privateVarOne in the init function also works (without the dump)

----------------------------- Additional Watson Details -----------------------------

Watson Bug ID:	3352745

External Customer Info:
External Company:  
External Customer Name: Tom VS
External Customer Email:  
External Test Config: My Hardware and Environment details:

Tested on several installations and pc. (all windows 7 64bit though)

Attachments:

Comments:

My work around is not to rely on default values for properties, rather always set defaults during init()... This should be fixed though as it is very annoying.
Comment by External U.
17369 | October 25, 2012 02:03:49 AM GMT
default values should be set consistently regardless how the cfc is being used/invoked
Vote by External U.
17380 | October 26, 2012 10:12:41 AM GMT
Verified in CF10 update 11 and CF11: MyTest.cfc component accessors="true" { property name="privateVarOne" default="privateVarOne default"; property name="privateVarOne1" default="privateVarOne default"; property name="privateVarOne2" default="privateVarOne default"; function init() { return this; } public void function newMethod() { writedump(variables); writedump(variables); writedump(var="success"); } } test.cfm <cfset test = new MyTest() /> <cfset test.newMethod() /> Run test.cfm dump variables twice in newMethod of MyTest.cfc component should show variables as a part of struct in first dump as shown in second dump. (Comment added from ex-user id:nawani)
Comment by Adobe D.
17370 | September 18, 2013 01:47:30 AM GMT
Property initialization of a CFC with accessor flag doesn't happen instantly and rather initialized later as and when used. In the above testcase, if somehow the implicit setter/getter are forced, say by invoking writedump(variables), everything will start working fine. This issue has to be fixed but its a bit late for this release cycle. Will take this up later. As a workaround, one can either call implicit getter methods for all the properties or dump the variables scope.
Comment by Awdhesh K.
17371 | March 04, 2014 03:39:31 AM GMT
+1 / subscribe -- Adam
Vote by External U.
17381 | September 01, 2014 03:05:51 AM GMT
The fix for this bug is available in the pre-release build of ColdFusion 11 Update 5 and ColdFusion 10 Update 16
Comment by CFwatson U.
17372 | February 20, 2015 09:22:49 AM GMT
Verified this is fixed in CF11 Update 5 (build 11,0,05,293506). The following repro shows cfproperty defaults finally work as expected: MyCFC.cfc ---------------- component accessors="true" { property name="myProperty1" default="myProperty1 default"; property name="myProperty2" default="myProperty2 default"; property name="myProperty3" default="myProperty3 default"; function myFunction() { return {myProperty1=variables.myProperty1, myProperty2=variables.myProperty2, myProperty3=variables.myProperty3}; } } index.cfm --------- <cfscript> o = new MyCFC(); writeDump(o.myFunction()); </cfscript> returns: ----------- struct MYPROPERTY1: myProperty1 default MYPROPERTY2: myProperty2 default MYPROPERTY3: myProperty3 default ----------- Nice!! =D Now, if you can please fix CF-3130900 (which CF-3337574 is a duplicate of). Thanks!, -Aaron
Comment by External U.
17373 | August 14, 2015 01:48:43 PM GMT
Correct me if I'm wrong, but the issue seems to persist when using createObject over the "new" operator. <cfscript> o = createObject("component", "Controller"); // ERROR //o = new Controller(); // OK WriteDump(var=o.myFunction()); </cfscript> Should I open a new ticket?
Comment by External U.
17374 | October 15, 2015 09:27:34 PM GMT
Hi Geoffrey, I've verified (in CF11 Update 5) that you're right. This ticket was only fixed for "new" but not createObject(). Adobe, Please re-open and fix fully. Thanks!, -Aaron P.S. Geoffrey, if Adobe doesn't reply in a few days, just create a new ticket please.
Comment by External U.
17375 | October 18, 2015 01:43:49 AM GMT
And, Geoffrey, if you create a new ticket, could you please post the ticket# here? Thanks!, -Aaron
Comment by External U.
17376 | October 18, 2015 01:45:00 AM GMT
Opened a new Bug CF-4076193.
Comment by External U.
17377 | October 19, 2015 05:22:03 PM GMT
Hi Geoffrey, Thanks and I've voted for it. -Aaron
Comment by External U.
17378 | October 21, 2015 02:46:52 PM GMT
Only works if value is constant. Works: default="a constant value" Fails: default="#now()#" Throws: "Expression in cfproperty value must have a constant value." Why?? Thanks!, -Aaron
Comment by External U.
17379 | May 07, 2016 12:16:13 AM GMT