Returning a CFC from a CFC Method

In an earlier post, I talked about returnType and CFCs. Specifically, I talked about how if you want to return a CFC from a CFC method, you simply use the name of the CFC in return type. What if you wanted to return a CFC, but you didn't care what CFC you returned? All CFCs extend one base component. You can see it in the hierarchy when you display a CFC:

WEB-INF.cftags.component

If you set returnType equal to this value, then you can return an instance of any CFC from your method.

Archived Comments

Comment 1 by Alex Sherwood posted on 9/24/2003 at 4:07 PM

What about using "struct" as a returnType?

Comment 2 by Raymond Camden posted on 9/24/2003 at 9:31 PM

While I think CFCs do return true for isStruct, I would not recommned using it as a returnType. It may work, but why be vague when you can be specific. If your method is supposed to return a CFC, I'd say use the exact name.

Comment 3 by Brendan posted on 10/1/2003 at 10:15 PM

This is only available now in 6.1. 6.0 Had no such master component so during that time you would have had to use struct.

Comment 4 by Raymond Camden posted on 10/1/2003 at 10:53 PM

There _was_ a root CFC in 6.0, but you couldn't edit it. That being said, I didn't test this in cf 6.0, so there is a chance it may not work.