I've run into a strange bug with CFC inheritance. It definitely seems to be a problem in ColdFusion 8, and I would be interested to see if it's a problem in CF9 also, but I haven't started using CF9 yet.
The problem comes up if you extend a CFC of the same name that is in a different directory. CFCs in different directories should be treated as completely different components, as far as I know, but something goes wrong if the file name is the same. For a simple test case, I created 3 CFCs:
/test/Test1.cfc
<cfcomponent output="false">
<cffunction name="Test" output="true">
Super Test
</cffunction>
</cfcomponent>
/Test1.cfc
<cfcomponent extends="test.Test1" output="false">
<cffunction name="Test" output="true">
Test
</cffunction>
</cfcomponent>
/Test2.cfc
<cfcomponent extends="test.Test1" output="false">
<cffunction name="Test" output="true">
Test
</cffunction>
</cfcomponent>
The first file is in a subdirectory, and the other two files are identical except for their names -- one of them is the same name as the first file, and the other one is different.
I created a fourth file with the following code:
<cfset CFC1 = CreateObject("component","test.Test1")>
<cfset CFC2 = CreateObject("component","test.Test2")>
<cfoutput>
<p>#CFC1.Test()#</p>
<p>#CFC2.Test()#</p>
</cfoutput>
What would you expect this file to output? I would expect:
Test
Test
Instead, I get:
Super Test
Test
In other words, even though /Test1.cfc overrides the Test function, it is ignored in favor of the function in /test/Test1.cfc. Test2.cfc, on the other hand, works correctly.
My first question, of course, is: Have I missed something? This sure seems like a glaring bug to me.
Update:
If the Test function is set to access="remote" and called directly from the browser like this:
/Test1.cfc?method=Test
Then it produces "Test" as expected. All other methods I have tried of calling the function produce "Super Test". Certainly a head-scratcher.
Posted on January 25, 2010 8:33:18 PM EST by David Hammond
Posted on March 8, 2010 7:15:14 PM EST by David Hammond
Comments have been disabled for this page.