Search code examples
coldfusioncfmlrailocfclucee

Including interface functions in cfc from cfml files on lucee or railo


I'm trying to add a interface to a cfc that includes some functions in a cfml file however it throws a error with the message "component [...] does not implement the function [..] of the interface" the function it's complaining about is implemented in the included cfml file, i've tested this in both railo 4 and lucee 5 and get the same error in both but it works in coldfusion 11 does anyone know if there is a workaround or fix for this in lucee or railo?

Below is example code that reproduces the error.

int.cfc

interface {
    public numeric function func() output="false";
}

comp.cfc

component implements="int" {
    include "inc.cfm";
}

inc.cfm

<cfscript>
public numeric function func() output="false"{
    return 2;
}
</cfscript>

index.cfm

<cfscript>
    cfc = createObject("component", "comp");
    writedump(cfc.func());
</cfscript>

Solution

  • One possible workaround i've found is to replace the original cfc that includes the cfml file with an empty cfc that implements the interface but also extends the original cfc renamed to something else, by replacing original cfc you can keep the same type while also adding the interface. So the updated parts of the example with the question would look like this

    comp-to-extend.cfc

    component implements="int" {
        include "inc.cfm";
    }
    

    comp.cfc

    component extends="comp-to-extend" implements="int" {}