The CFOBJECT tag is used to create an instance of the object and other ColdFusion tags, such as CFSET and CFOUTPUT, are used to invoke properties (attributes), and methods (operations) on the object. An object created by CFOBJECT or returned by other objects is implicitly released at the end of the template execution.
The following coding practice is required (or recommended) when accessing the object. Assume that the NAME attribute in the CFOBJECT tag specified the value "obj", and that the object has a property called "Property", and methods called "Method1", "Method2", and "Method3".
![]() |
To set a property: |
<CFSET obj.property = "somevalue">
![]() |
To get a property: |
<CFSET value = obj.property>
Note that parentheses are not used on the right side of the equation for property-gets.
Object methods usually take zero or more arguments. Arguments can be sent by value ([in] arguments) or by reference ([out] and [in,out]). Arguments sent by reference usually have their value changed by the object. Some methods return values while others may not.
<CFSET retVal = obj.Method1()>
Note that parentheses are required for methods with no arguments.
<CFSET x = 23> <CFSET retVal = obj.Method1(x, "a string literal")>
This method accepts one integer argument, and one string argument.
<CFSET x = 23> <CFSET retVal = obj.Method2("x", "a string literal")> <CFOUTPUT> #x#</CFOUTPUT>
Note the use of double-quotes ("") to specify reference arguments. If the object changes the value of "x", it will now contain a value other than 23.
The current release of ColdFusion does not support nested (scoped) object calls. For example, if an object method returns another object and you would like to invoke a property/method on that object, the following is required:
<CFSET objX = myObj.X> <CFSET prop = objX.Property>
(That is, the syntax <CFSET prop = myObj.X.Property>
will fail.)