Using the features of the included file makes coldfusion import forgotten. This is normal?

I noticed that when I call the function of the previously included (cfinclude) .cfm file, all the cold words (cfimport) imported into it are forgotten. As if you didn’t import anything. I found this very strange behavior, so I isolated it, but the results remained the same, even in coldfusion 10.

My setup:

/Example

  • functions.cfm
  • index.cfm
  • /Components
    • Mycfc.cfc

functions.cfm:

<cfscript> function test(){ return "test"; } </cfscript> 
code>

components / MyCFC.cfc:

 component output="false"{} 

index.cfm:

 <cfscript> include "functions.cfm"; import components.MyCFC; 
foo = test(); bar = new MyCFC(); </cfscript>
code>

This code will throw a coldfusion error: "Could not find ColdFusion component or MyCFC interface." when foo = test(); deleted or placed after bar = new MyCFC(); The code works very well.

It does not matter if the import is placed before or after inclusion. Whenever a function is enabled, the import is forgotten.

Is this a mistake or should it behave this way?

Tested with cold administration of 9,0,0,251028 and coldfusion 10,282462

+4
source share
2 answers

Since I am doing a lot of imports, I recently met some odd behavior and reported that it does CF9-bugbase: https://bugbase.adobe.com/index.cfm?event=bug&id=3288035

ColdFusion only allows import for the current file, and whenever you call another file, it resembles a "run context" that switches to import files. Therefore, in your case, when you execute new ColdFusion functions in functions.cfm for import. When you call the method of the current file, it switches back and finds the import.

If I'm right, your code should work if you do bar = new MyCFC(); immediately after import. Or you can define another method in index.cfm and call it before creating the class.

To get around this error, you need to make sure that import is enabled (the first time you use objects in the life cycle) before the "context switch" occurs. So call new MyCFC(); before the external method.

@Adobe: It would be nice to fix this;)

+3
source

I'm with @PeterBoughton, that sounds like a bug. I could not find the same error being reported, so I would continue it. At the same time, if you refuse to import, you can still reference CFC using:

 bar = new components.MyCFC(); 

Great catch!

+1
source

Source: https://habr.com/ru/post/1435921/


All Articles