When the Obvious is TOO Obvious - A Lesson in Troubleshooting
Look at the following code and guess what the output would be:
<cfset newstring = strObj.getString() />
<cfoutput>#newstring#</cfoutput>
Oh, here's the cfc...
<CFFUNCTION NAME="init" ACCESS="public" RETURNTYPE="makestring">
<CFRETURN this>
</CFFUNCTION>
<CFFUNCTION
NAME="getString"
ACCESS="public"
RETURNTYPE="string">
<CFSET var thisString = "" />
<CFSAVECONTENT
VARIABLE="thisString">
<ul>
<li>list item 1</li>
<li>list item 2</li>
<li>list item 3</li>
</ul>
</CFSAVECONTENT>
<CFRETURN thisString />
</CFFUNCTION>
</CFCOMPONENT>
Choices:
- A:[empty string]
- B:
- list item 1
- list item 2
- list item 3
- C:depends
The correct answer is C, and what it depends on is whether or not somewhere else within your application a CFSETTING tag is lurking that has ENABLECFOUTPUTONLY set to 'Yes'. If this attribute is in effect, then your result will be A; if it's not, your result will be B.
The reason I felt the need to post on this is the fact that I spent a few hours yesterday developing a mild headache trying to figure out why my perfectly simple cfc was producing an empty string at one point within my app, but the correct string elsewhere. Through experimentation and noting that when I removed the CFSAVECONTENT tags everything worked as designed, I eventually concluded that I MUST have discovered a bug in the framework I was using, and so notified the keepers of the framework of all the details of my investigation and conclusion, along with code samples. They immediately (and nicely) informed me that more likely it was the fact that I had ENABLECFOUTPUTONLY enabled, and that I hadn't included CFOUTPUT tags within my CFC method. With egg still dripping from my face, I added the CFOUTPUT tags to my method and wouldn't ya know it...it worked.
I still haven't taken the time to find out where within this app the CFSETTING tag is being called, but two lessons gleaned here for me:
- Next time I feel excited at the prospect of having discovered a "bug", I'll think again (nobody wants the reputation of being The Boy Who Cried 'Bug!');
- Start troubleshooting from 10,000 feet instead of with a magnifying glass.


As a side note, you should also globally check your files for the <cfsilent> tag. It has a similar effect in that it hides the normal (non cfoutput) html.
Thanks for pointing that out Chris, I'll git 'er fixed.