Copy link to clipboard
Copied
I've been working with the isInstanceOf() method a lot and found that it does not work in ColdFusion 9 the way it has in previous versions.
I've created a set of inherited objects. Admin inherits from Member which inherits from User. In ColdFusion 9, I'll create an Admin session object - called thisAdmin - and the following code produces only the word "Admin", instead of "Admin Member User":
<CFIF isInstanceOf(SESSION.thisAdmin, "authentication.components.admin")>
Admin
</CFIF>
<CFIF isInstanceOf(SESSION.thisAdmin, "authentication.components.member")>
Member
</CFIF>
<CFIF isInstanceOf(SESSION.thisAdmin, "authentication.components.user")>
User
</CFIF>
This behaves as you'd expect in ColdFusion 8 - producing "Admin Member User". It's frustrating the ColdFusion 9 doesn't work as well as previous versions in this area. Any of you run into this problem? Any ideas on what I'm doing wrong?
Copy link to clipboard
Copied
You don't really provide us with a complete reproduction case here, so I've had to guess at some of your code, but it works fine (and as you'd expect/want it to) for me.
Can you post a proper / complete reproduction case so I can see what you're doing?
Here's my repro case, by way of exmaple of what you should be posting:
<!--- User.cfc --->
<cfcomponent>
</cfcomponent>
<!--- Member.cfc --->
<cfcomponent extends="User">
</cfcomponent>
<!--- Admin.cfc --->
<cfcomponent extends="Member">
</cfcomponent>
<!--- testInheritance.cfm --->
<cfset o = createObject("component", "Admin")>
<cfif isInstanceOf(o, "Admin")>
<cfoutput>It's an Admin<br /></cfoutput>
</cfif>
<cfif isInstanceOf(o, "Member")>
<cfoutput>It's a Member<br /></cfoutput>
</cfif>
<cfif isInstanceOf(o, "User")>
<cfoutput>It's a User<br /></cfoutput>
</cfif>
Output:
It's an Admin
It's a Member
It's a User
When working through this sort of problem, one should always pare the situation down to this sort of level so as to remoev as many contributing factors as possible. Then add potential contributing factors back in until one identifies the problem.
--
Adam
Copy link to clipboard
Copied
Another suggestion, related to Adam's: did you write <cfcomponent extend="Member"> by mistake instead of <cfcomponent extends="Member">?