Reputation: 507
Assuming the following code in a regular .cfm file, not a CFC:
<cffunction name="myFunction"> <cfobject type="java" action="create" class="path.to.my.java.class" name="myJavaVariable"> </cffunction>
What is going to be the scope of the created object? I'm getting the feeling it's not limited to the function scope. If so, how to make it local? Would the following work?
<cfset var myJavaVariable = ""> <cfobject ... name="myJavaVariable">
EDIT: I forgot to say I was under Coldfusion MX 7, as it does prevent some useful solutions found on the web from working.
I did find a workaround where one creates a fake local scope (<cfset var local = StructNew()>
). It does work well even for such tags since you can put the return variable as local.someVar
.
Upvotes: 2
Views: 216
Reputation: 29870
I'd question why you're using <cfobject>
at all, rather than the more obvious simple assignment:
var myJavaVariable = createObject("java", "path.to.my.java.class");
Isn't that more natural code anyhow?
Upvotes: 9