Defines a function call

This tag must have a body.

This tag is also supported within <cfscript>

<cffunction name=string returntype=string bufferoutput=boolean roles=string access=string output=boolean displayname=string hint=string abstract=boolean description=string returnformat=string securejson=boolean verifyclient=boolean localmode=string cachedwithin=object modifier=string ><!--- body ---></cffunction>
Attribute Description
string, required

A string; a component method that is used within the cfcomponent tag.

string, optional

String; a type name; data type of the function return value

boolean, optional

This attribute is only used when output of the function is set to false. If this attribute is set to true (default) the output written to the body of the function is buffered and in case of an exception also outputted.

If set to false the content to body is ignored and not disabled when a failure in the body of the tag occur.

string, optional

This attribute is used only for a component. If this attribute is omitted, all roles can invoke the method.

string, optional

This attribute is used only within a component. The client security context from which the method can be invoked

  • remote
  • public
  • package
  • private
boolean, optional

This attribute is used only for a component.

  • yes: the function is processed as if it were within a <cfoutput> tag
  • no: the function is processed as if it were within a <cfsilent> tag
string, optional

Display Name of the Function

string, optional

Hint of the Function

boolean, optional

is the function abstract or not, abstract functions are only allowed inside interface or component tags

string, optional

Supplies a short text description of the function.

string, optional

The format in which to return values to a remote caller.

Supported values are

  • [wddx]
  • json
  • plain (text)
  • serialize (cfml, cfm)
  • xml
  • java
boolean, optional

A Boolean value that specifies whether to add a security prefix in front of any value that the function returns in JSON-format in response to a remote call.

boolean, optional

A Boolean value that specifies whether to require remote function calls to include an encrypted security token. For use with AJAX applications only.

string, optional

Defines how the local scope of this function is invoked when a variable with no scope definition is used. Accepted values include:

  • classic (default): The local scope is only invoked when the key already exists in it (also aliased as false).
  • modern: The local scope is always invoked (also aliased as true).
object, optional

possible values are:

  • String "request": If original content was created within the current request, cached content data is used.
  • a timespan (created with CreateTimeSpan()): If original content date falls within the time span, cached content data is used.

To use cached data, the function must be called with the exact same arguments (part of the cache key is a hash of the arguments)

string, optional

Use modifier to denote a function as abstract, static or final.

  • abstract: implementation must be defined in extended component.
  • final: implementation cannot be extended.
  • static: does not access instance variables in the component.


Simple Example with tag format

<cffunction access="private" name="add">
		<cfargument name="arg1" type="Numeric" required />
		<cfargument name="arg2" type="Numeric" required />
	 	<cfreturn arg1 + arg2 />
	<cfdump var="Define function Using tag.It returns :#add(4,2)#" />

Simple Example with script format

writeDump("Define function using cfscript. It returns: "&add(2,3));
		public function add(required numeric arg1,required numeric arg2){
			return arg1+arg2;

See also