ColdFusion Method Definitions Can Come After The Code That References Them

Posted February 20, 2007 at 8:48 AM by Ben Nadel

Tags: ColdFusion

Well, not always, but sometimes. I always thing about ColdFusion as a top-down processing system. And, it is. But what I forget is that the page gets compiled before it gets run. Because of that (or at least this is what I am assuming), ColdFusion methods that are declared within a given template can come AFTER the code that references them so long as that reference is also in the same template.

In other words, this runs perfectly well:

  • <!--- Get some reassurance. --->
  • #GetReassurance( "Am I good enough?" )#
  •  
  • <cffunction
  • name="GetReassurance"
  • access="public"
  • returntype="string"
  • output="false"
  • hint="Reassures you that you are good enough.">
  •  
  • <cfreturn "Look dude, you are the man! Don't fight it." />
  • </cffunction>

Logically, I would expect that page to fail as the line that calls GetReassurance() is referring to a user defined method that has not yet been defined. But, since this method gets compiled with the page, I guess same-template references do not require a particular order.

If the ColdFusion user defined method was put into a CFInclude, this would fail. This only works if the method is defined IN THE SAME PAGE.



Reader Comments

Feb 20, 2007 at 9:44 AM // reply »
30 Comments

Right you are. In fact, even if you put a cfabort after your udf call and before your udf definition, I believe your call well execute successfully under most circumstances. Obviously if your udf references global variables defined after the cfabort, that probably wouldn't be the case.


Feb 20, 2007 at 9:45 AM // reply »
30 Comments

That should be "your call will execute." I haven't had my coffee yet this morning. :-)


Feb 20, 2007 at 10:02 AM // reply »
50 Comments

That is cool! I would have assumed that wouldn't have worked. I wonder if ColdFusion loads UDFs in the parsing stage?


Feb 20, 2007 at 10:09 AM // reply »
11,238 Comments

I think UDFs get loaded as actual Java classes right? I guess they get compiled down to separate java byte code before the pages starts running. Of course I know nothing about that aspect, so I may be way off the mark.


Feb 20, 2007 at 10:21 AM // reply »
30 Comments

Ben, I think you're right. I know that is the case with functions in CFCs, so I would think it would be similar for plain ol' CFM files.


Post A Comment

Comment Etiquette: Please do not post spam. Please keep the comments on-topic. Please do not post unrelated questions or large chunks of code. And, above all, please be nice to each other - we're trying to have a good conversation here.

Please review the following issues:

Author Name:


Author Email:

Author Website:

Comment:

Supported HTML tags for formatting: <strong>bold</strong>   <em>italic</em>   <code>code</code>







  • Help Wanted - Find Your Next ColdFusion Job
Ben Nadel's Company - Epicenter Consulting Recent Blog Comments
May 19, 2013 at 2:31 PM
My Experience With AngularJS - The Super-heroic JavaScript MVW Framework
It's funny really just how well that image describes the way I would imagine most people that go with angular for some project is. I have had a similar roller-coaster ride with it as well, but not qu ... read »
May 17, 2013 at 7:42 PM
HashKeyCopier - An AngularJS Utility Class For Merging Cached And Live Data
Ben - thanks so much for posting these Angular articles and findings, they've been a huge help towards learning one of the more 'complex' JavaScript frameworks out there (IMO). I have been using Angu ... read »
May 16, 2013 at 5:01 PM
UPDATE: Parsing CSV Data Files In ColdFusion With csvToArray()
Your code was the closest thing I've found to obtaining some direction for converting ISO fields to values that CF can translate properly. Thank you for posting! ... read »
May 15, 2013 at 10:37 PM
Very Simple Pusher And ColdFusion Powered Chat
hi id making plz easy ... read »
May 15, 2013 at 6:07 PM
Making SOAP Web Service Requests With ColdFusion And CFHTTP
Ben, you once again saved my bacon at work. Thank you, thank you, thank you! ... read »
May 15, 2013 at 4:15 PM
What If All User Interface (UI) Data Came In Reports?
@Josh, Thanks! @Ben, I definitely recommend the David West book "Object Thinking" I've been quoting from. It goes deeply into the philosophy and history of OO programming. His breadth ... read »
May 15, 2013 at 11:36 AM
Ask Ben: Print Part Of A Web Page With jQuery
I found this helpfull when you need to keep (refresh) the original parent page after closing the iframe child print dialog (Hoping you're not using a form at this time so it won't submit again): On ... read »
May 14, 2013 at 7:13 PM
What If All User Interface (UI) Data Came In Reports?
@Jonah, If there's any books you'd recommend on the subject of domain modelling, I'd love to hear it. I just downloaded the free PDF of "Domain Driven Design Quickly". Figured I'd give it ... read »
InVision App - Prototyping Made Beautiful With Prototyping Tools