Jul 08

Reserved ColdFusion function names

Posted by James Netherton | Tuesday 08 July 2008 8:55 PM | In ColdFusion

Most people are aware that you cannot give a name to a ColdFusion function that is equal to the name of one of the ColdFusion "built in" functions.

This started me thinking that as ColdFusion templates and CFC's are compiled down to Java servlets, there must be additional function names that are 'reserved'. Each template and CFC page will naturally extend java.lang.Object and therefore inherit all of Object's public methods.

For example, try the following:

<cffunction name="getClass">
</cffunction>

The result is "The name getClass is the name of a built-in ColdFusion function". You get the same result when declaring a function with the names "wait", "notify" and "equals", all of which are public methods on java.lang.Object.

These are only a few examples, I'm assuming that there must be more reserved function names given the number of classes that ColdFusion template and CFC servlets could potentially extend from.

The getClass method opens up the potential for some fun with ColdFusion:

Get the current template class name

<cfoutput>#getClass().getName()#</cfoutput>

Get the current template class properties

<cfset fields = getClass().getFields()/>

<cfloop array="#fields#" index="field">
   <cfoutput>#field.getName()#<br/></cfoutput>
</cfloop>

Get the current template class methods

<cfset methods = getClass().getDeclaredMethods()/>

<cfloop array="#methods#" index="method">
   <cfoutput>#method.getName()#<br/></cfoutput>
</cfloop>

Get the name of the class that the current template extends from

<cfoutput>#getClass().getSuperclass().getName()#</cfoutput>

 

0 Comments

[Post comment]


Leave a comment








Captcha text