GetFunctionCalledName

Description

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

Returns

Name of the variable.

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>