Skip to main content
Owainnorth
Inspiring
June 6, 2011
Answered

<cfcomponent output="false">

  • June 6, 2011
  • 2 replies
  • 4423 views

Not something I've really looked into that much before, but what does this actually do?

If you do this:

<cffunction output="false"> then it supresses output from the method.

I would therefore expect that <cfcomponent output="false"> supresses output from the entire cfc, but it doesn't seem to. So what's the point? There doesn't seem to be anything in the docs about it (or at least not that I can find) and Googling didn't bring out much.

As I'd imagine the vast majority of methods and cfcs give no output, it seems a bit odd that output="true" is the default. Anyone got any thoughts?

    This topic has been closed for replies.
    Correct answer Adam Cameron.

    The OUTPUT attribute of the CFCOMPONENT tag suppresses output from the "pseudo-constructor" code: code that is within the CFCOMPONENT tags, but outwith any CFFUNCTION tags.  This code is run when the CFC is instantiated.

    OUTPUT for CFCOMPONENT loks like it's a boolean, but it's actually tri-state:

    OUTPUT=TRUE: behaves as if the whole thing is wrapped in CFOUTPUT tags

    OUTPUT=FALSE: behaves as if the whole thign is wrapped in CFSILENT tags

    OUTPUT=[not specified] behaves like normal CFML code: will output plain text, but to resolve dynamic values (eg: stuff within hash-marks / pound-signs), one needs to use CFOUTPUT tags.

    I guess this is why it's not CFOUTPUT=FALSE by default.  If that was the default, then there'd be no way of reflecting that third state.

    If I was architecting the CFC implementation, it'd be output=false by default, and if output=true then the code would act like any normal CFML: so like the current [not specified] behaviour.  I think the way OUTPUT=TRUE behaves is stupid: who the hell would want ALL their code in CFOUTPUT tags?

    Does that answer your question(s)?

    --

    Adam

    2 replies

    July 27, 2011

    I believe setting output = 'false" in cfcs also helps prevent memory leaks (and heap dumps). I am not sure if CF9 does this or not as I always add the output = 'false" in the cffunction.

    Hope it helps,

    Bill

    Adam Cameron.Correct answer
    Inspiring
    June 6, 2011

    The OUTPUT attribute of the CFCOMPONENT tag suppresses output from the "pseudo-constructor" code: code that is within the CFCOMPONENT tags, but outwith any CFFUNCTION tags.  This code is run when the CFC is instantiated.

    OUTPUT for CFCOMPONENT loks like it's a boolean, but it's actually tri-state:

    OUTPUT=TRUE: behaves as if the whole thing is wrapped in CFOUTPUT tags

    OUTPUT=FALSE: behaves as if the whole thign is wrapped in CFSILENT tags

    OUTPUT=[not specified] behaves like normal CFML code: will output plain text, but to resolve dynamic values (eg: stuff within hash-marks / pound-signs), one needs to use CFOUTPUT tags.

    I guess this is why it's not CFOUTPUT=FALSE by default.  If that was the default, then there'd be no way of reflecting that third state.

    If I was architecting the CFC implementation, it'd be output=false by default, and if output=true then the code would act like any normal CFML: so like the current [not specified] behaviour.  I think the way OUTPUT=TRUE behaves is stupid: who the hell would want ALL their code in CFOUTPUT tags?

    Does that answer your question(s)?

    --

    Adam

    Owainnorth
    Inspiring
    June 6, 2011

    I believe it does, yes. Have a "correct answer", whatever that means for anyone

    I'm just working on a new project so I'm trying writing all the cfcs in cfscript purely to see how well it works for me, and having to put in "output=false" statements everywhere just seems just such a waste of time and space.

    Why anyone would have code in a cfc outside a method that renders output to a page I really do have no idea.

    Ta muchly.

    Inspiring
    June 6, 2011

    Now... when you say you're doing them in CFScript, do you mean as per CF9's new "script-only CFCs"?  You can almost get away with not bothering with OUTPUT=FALSE in that case, as CFScript doesn't generate spurious output like tags do.

    The only thing to watch for is if within your script-only CFC you call a non-script CFC method which doesn't have output suppressed: then its spurious output could still bleed out.

    --

    Adam