I hope someone can explain this behavior, as I find it rather aggravating. I have a parent class with an OnMissingMethod implementation to provide implicit getters / setters (old CF8 application)
If I create a child class as foo and call foo.getBar () from an external file, it successfully runs OnMissingMethod, but if inside the class foo I call getBar () - no. The only way to call OnMissingMethod is to use if I use this.getBar () , which I don't like about aesthetic considerations and code inconsistencies.
TL; DR; here is a sample code ... try it yourself.
Foo.cfc
<cfcomponent output="false" extends="Parent"> <cffunction name="init" output="false" returntype="Foo"> <cfreturn this /> </cffunction> <cffunction name="getInternalBar_workie"> <cfreturn this.getBar() /> </cffunction> <cffunction name="getInternalBar_noworkie"> <cfreturn getBar() /> </cffunction> </cfcomponent>
Parent.cfc
<cfcomponent output="false"> <cffunction name="OnMissingMethod"> <cfreturn true /> </cffunction> </cfcomponent>
foobar.cfm
<cfset foo = CreateObject( "component", "Foo").init() /> <cfdump var="#foo.getBar()#" /><br/> <cfdump var="#foo.getInternalBar_workie()#" /><br/> <cfdump var="#foo.getInternalBar_noworkie()#" />
Can someone explain why the 'this' scope should be used for OnMissingMethod to work correctly when called from the class itself? Is there a better workaround?
source share