Outputting Content From Within a Method
Normally I’m with the crowd who says “don’t output content or use
Still, the other day I found myself doing what I don’t normally do…wanting to output a simple text value from within a method.
My scenario was quite complex so I won’t go into all the details, suffice to say that there were several methods being called eventuating in a final method call to display().
The display() method was outputting a simple string value (yikes!). Now the actual problem I encountered was that my output wasn’t actually displaying :(
I had output=”true” in the display() method but nothing was showing. It took me a few minutes to trace through the code and discover that because display() was being called from another function (and I wanted to output a value from within display(), that the initial functions output attribute also needed to be set to true. This I did not know.
So the following will not work because output is set to false in function1():
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
But if you change the output attribute to true:
Now if only I kept true to my rule of not outputting content in a method…