I was talking to Michael Dinowitz last night at the NY-CFUG about the ColdFusion CFSetting attribute, EnableCFOutputOnly. We had just seen an example where a ColdFusion user defined function had its "Output" attribute set to "True" and also had CFOutput tags inside the method body as well. Michael argued that this was redundant as the Output attribute did just that - created a CFOutput-like environment. I agreed that this was true, except for when EnableCFOutputOnly was turned on; in that case, the additional CFOutput was required. I think he disagreed, but I don't quite remember. Regardless, here is the test:
Launch code in new window » Download code as text file »
As you can see, part of the content is wrapped in a CFOutput tags and part of it relies on the OUTPUT=TRUE attribute of the ColdFusion user defined method. Running the above code gives us:
This value should be output:
Now, if we go in and update the UDF to have a CFOutput tag:
Launch code in new window » Download code as text file »
... and then run the code again, we get:
This value should be output: Stars When you shine, you know how I feel.
So, you can see here that OUTPUT=TRUE in a method has no effect if CFSetting has EnableCFOutputOnly enabled.
But, that's settings and methods that are in the same variables scope, if you will (not sure how else to say that). One of the other things that I discussed very briefly with Michael was the affect of CFSetting on a separate object such as a CFC or a custom tag. Again, I am not sure we agreed on this.
To test, I created a CFC for testing output both to the SAME output buffer and also to a completely separate file buffer:
Launch code in new window » Download code as text file »
Now, let's tweak the original code to use the Test ColdFusion component:
Launch code in new window » Download code as text file »
Running this, again we get:
This value should be output:
But, now, if we check the "cfoutput_test.txt", we get this:
Value:
As you can see, with the CFSetting EnableCFOutputOnly attribute enabled, it affects not only things in the same scope and output buffer, but ALL calls made during that request (after the CFSetting tag of course) including buffers built for CFFile usage. Very interesting. This goes to show you that you should be very careful when using EnableCFOutputOnly as its effects are quite far reaching.
Download Code Snippet ZIP File
Comments (4) | Post Comment | Ask Ben | Permalink | Other Searches | Print Page
Dealing With RequestTimeOut And The OnError Application Event Method (Help Me)
Testing For NULL Values In A ColdFusion Query Result Set
What I had said was that UDFs and CFCs run in their own 'space' and what happens within them should not be effected by a CFSETTING. On the other hand, the content outputted to the page would be affected. I've run some tests that got very different results than what you have.
Oh, and the term argued seems to be a loaded one. We whispered it back and forth during a presentation. :)
Posted by michael dinowitz on Feb 20, 2007 at 3:35 PM
Shhhhhh! You don't want people knowing we weren't paying attention :)
Yes, I did not mean "arguing". Just that we were discussing (over the span of about 7 seconds). Personally, I hope that your opinion is more correct as it seems silly to me that a CFSetting in one file should affect the CFFile action of component... something ain't right about that (though I guess you could argue both ways).
Posted by Ben Nadel on Feb 20, 2007 at 3:40 PM
weren't paying attention? I think the two of us were responsible for at least half of the 'write it down to ask later' questions. Some of our questions will either go to BD docs or make them rewrite parts of their server core. :)
I'm still seeing strange results from my tests that still say that UDFs are not effected by CFSETTING. On the other hand, assigning a UDF result to a variable on a page with a CFSETTING seems to be effected.
Really strange.
Posted by michael dinowitz on Feb 20, 2007 at 3:50 PM
Note: Both Michael and I seemed to be on the right track - depending on variable usage. Michael is logging this inconsistent behavior as a bug.
Posted by Ben Nadel on Feb 20, 2007 at 3:56 PM