Ask a Jedi: Impact of whitespace and script based CFCs

This post is more than 2 years old.

Henry asks:

Does CF9 script style CFC still needs to set attribute output=false for component and function?

In my - admittedly - very limited testing, the answer appears to be no. I created a component with a large amount of white space in both the function and around it as well:

component {

public string function sayHello() {

return "Hello World!";



I duplicated this component but added output="false" to both the component and method:

component output="false" {

public string function sayHello() output="false" {

return "Hello World!";



To test then I created an instance of both and wrapped the sayHello call:

<cfset badWS = new testws()> <cfset goodWS = new testws2()>

<cfoutput> Testing bad: -#badWS.sayHello()#-<br/> Testing good: -#goodWS.sayHello()#-<br/> </cfoutput>

The result was the exact same. No additional white space from the creation of the CFC or the call either. I even tested making an instance of the first CFC with createObject, just to see if it made a difference, and it did not. Of course, it isn't like the output="false" argument is ignored. If you write a CFC method that outputs directly to the screen, then it does matter. Consider:

public function sayHello2() { writeOutput("hello2!"); }

That function will work just fine, but if you modify it a bit...

public function sayHello2() output="false" { writeOutput("hello2!"); }

Now you have a useless function. The output="false" will suppress the writeOutput>

Raymond Camden's Picture

About Raymond Camden

Raymond is a developer advocate for HERE Technologies. He focuses on JavaScript, serverless and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA