Whatever message this page gives is out now! Go check it out!

GetFunctionCalledName

Last update:
May 18, 2026

Description

Returns the name of the variable used to call a defined function.

Returns

Name of the variable.

Category

Function syntax

GetFunctionCalledName()

History

ColdFusion 9: Added this function

Usage

This function can be used to return data from CFCs by simulating getters and setters. This applies only if the CFC does not use implicit getters and setters provided by ColdFusion 9.

Example

The following example shows how you can use this function to return data without defining explicit setters and getters:
//callednamedemo.cfc 
 component 
 { 
 variables.x1 = 1; 
 variables.y1 = 2; 
 function init() 
 { 
 return this; 
 } 
 function get() 
 { 
 var name = getFunctionCalledName(); 
 return variables[mid(name,4,len(name)-3)]; 
 } 
 function set(value) 
 { 
 var name = getFunctionCalledName(); 
 variables[mid(name,4,len(name)-3)] = value; 
 } 
 this.getX1 = get; 
 this.getY1 = get; 
 this.setX1 = set; 
 this.setY1 = set; 
 } 
 <!--- calledname.cfm ---> 
 <cfscript> 
 function test() 
 { 
 return getFunctionCalledName(); 
 } 
 WriteOutput(test() & "<br>"); // test 
 a = test; 
 WriteOutput(variables.a() & "<br>"); // a 
 o = new callednamedemo(); 
 // shows *real* methods get(), SetX1() and getY1(), etc. 
 writeDump(o); 
 o.setX1(10); 
 o.setY1(20); 
 WriteOutput(o.getX1() & "<br>"); // 10 
 WriteOutput(o.getY1() & "<br>") ; // 20 </cfscript>

Share this page

Was this page helpful?
We're glad. Tell us how this page helped.
We're sorry. Can you tell us what didn't work for you?
Thank you for your feedback. Your response will help improve this page.

On this page