In CF10, I want to access a variable Test object using onMissingMethod function in TestHelper object, but I am getting an error.
Test.cfc
component {
public Any function init(){
instance = { x = 1 };
return this;
}
public numeric function getX(){
return instance.x;
}
}
TestHelper.cfc
component {
public Any function init( ){
variables.testObj = new Test();
return this;
}
public any function onMissingMethod( required string missingMethodName, required struct missingMethodArguments ){
var func = variables.testObj[ arguments.missingMethodName ];
return func( argumentCollection = arguments.missingMethodArguments );
}
}
Calling the object
obj = new TestHelper();
writeOutput( obj.getX() ); //Element INSTANCE.X is undefined in VARIABLES
In CF10, this gives me an error that element X is undefined in instance. It doesn't seem to recognize the variable instance. I could explicitly define getX function in TestHelper, but I was hoping I could use the onMissingMethod function.
Am I misunderstanding how onMissingMethod supposed to work here? FWIW, the code works in Railo.