3

I have two simple CFCs as shown below:

Test1.cfc

<cfcomponent> 
  <cffunction name="initMethod1" access="private" returntype="boolean"> 
  <cfreturn true />
</cfcomponent>

Test2.cfc

<cfcomponent> 
  <cffunction name="initMethod2" access="private" returntype="boolean"> 
  <cfreturn true />
</cfcomponent>

During OnApplicationStart() of Application.cfc, I make the following calls:

<cfset application["Test1"] = CreateObject("component","jbx.c.Test1") />
<cfset application["Test2"] = CreateObject("component","jbx.c.Test2") />

When I dump the application scope, notice below that both components have their own function as well as the other one's function. Any idea why this is and how to correct it? Thanks.

Test 1 Object http://www.signaturehairbyrisa.com/test1.png

Test 2 Object http://www.signaturehairbyrisa.com/test2.png

JRomeo
  • 543
  • 1
  • 4
  • 20
  • 7
    You say in a comment below that the code you posted above is not the actual code you were running ("Something I did not include in the code above is that those two components actually extend another..."). Please post the *exact* code that replicates this. – Adam Cameron Nov 18 '13 at 07:03
  • Did you check to see if this is a display issue only? The way to do that would be to try to run test2's method from the test1 object. – Dan Bracuk Nov 18 '13 at 12:56
  • What version of CF is this on? Can you pls update the tagging (and probably remove all the other ones, leaving just "ColdFusion" and "ColdFusion-x". The question isn't really about general inheritance, components or "extends". It's just a CF usage question. – Adam Cameron Nov 18 '13 at 13:39

1 Answers1

0

Because you tied this with onApplicationStart(), they were create when you first hit that web site. A quick way to reset the application variables is to rename the application.

When I develop cfc's that I know are going to be in the application scope, I work out all the details within the request scope, then once that is working right, I move the the application scope.

Another thing that is useful for debugging these kinds of issues, is to have

application.initialized = now();

That way when you do a dump of the application scope, you know when it was setup.

James A Mohler
  • 11,060
  • 15
  • 46
  • 72
  • Thanks for the quick reply. I set the application name to be created at random, created these objects in the request scope instead of application scope, and even bounced CF services, only to get the same condition. – JRomeo Nov 18 '13 at 05:09
  • It sounds like some cacheing is going on. Put a syntax error in one, and I bet you will still be able to "create" the object. This will confirm that you have a cacheing issue. Check the CF admin to make sure that component cache is turned off. – James A Mohler Nov 18 '13 at 05:25
  • Thanks for looking into this. I took your suggestions to determine that this is not a cache issue. Something I did not include in the code above is that those two components actually extend another component using extends="someSuperClass". However, when instantiating them as described above, even those without the extends attribute are inheriting the super class functions. – JRomeo Nov 18 '13 at 05:51
  • Put a syntax error into one of them. Put an extra function in the other, and see what happens – James A Mohler Nov 18 '13 at 05:56
  • I moved this codebase to a different server, and I'm still scratching my head, but everything works fine there. Though both CF9, the first server is the developer edition. Thanks again. – JRomeo Nov 18 '13 at 06:08
  • In each of your cfc's put in `this.templatepath= GetCurrentTemplatePath()` If it isn't a cacheing issue, it might be a path issue. – James A Mohler Nov 18 '13 at 06:21
  • 8
    I don't see how this answer is actually an answer to your issue (although it is marked as such), as by the sounds of it you never actually got to the bottom of what was going on? – Adam Cameron Nov 18 '13 at 07:02