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,314 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
Jun 18, 2013 at 9:20 PM
Mapping AngularJS Routes Onto URL Parameters And Client-Side Events
I couldn't find examples of passing multiple arguments using the when() routing statement so figured out through trial and error that you can pass multiple arguments using the following format: .whe ... read »
Jun 18, 2013 at 3:39 PM
Experimenting With The Amazon Simple Storage Service (S3) API Using ColdFusion
Hi Ben, THANKS! While not bleeding edge, it is new to me & I like learning new things every day! ... read »
Jun 18, 2013 at 12:30 PM
Disabling Auto-Correct And Auto-Capitalize Features On iPhone Inputs
Also spellcheck="false" should be mentioned as part of html5 specs ... read »
Jun 18, 2013 at 8:40 AM
Using Named Functions Within Self-Executing Function Blocks In Javascript
Hi Ben, you forgot to mention the most important thing for named self-executing functions - they can be referenced by name ONLY inside their execution context (which is parens in this case), it mean ... read »
dee
Jun 18, 2013 at 7:01 AM
My Safari Browser SQLite Database Hello World Example
hai ben, this program is really good i could understand the concept but i dint know how to save it and how to open it as you have done in the video can u give that details pls ... read »
Jun 18, 2013 at 6:04 AM
Clearing Inline CSS Properties With jQuery
Thanks a lot for for post! It helped me a lot... after being stuck since 24 hrs.. found solution from your post. Thanks again! ... read »
Jun 18, 2013 at 2:31 AM
SOTR 2013 - The Best Conference I Never Went To
I keep watching it, should keep me happily distracted until SotR14 ;) ... read »
Jun 17, 2013 at 9:45 PM
What If All User Interface (UI) Data Came In Reports?
@Jonah, As I was reading what you wrote, it occurred to me that maybe I do something similar to that in some of my client-side code. In an application I'm working on, there are a bunch of unrelated ... read »
InVision App - Prototyping Made Beautiful With Prototyping Tools