Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

isInstanceOf() behavior in CF 9

New Here ,
Jul 18, 2011 Jul 18, 2011

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?

392
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 21, 2011 Jul 21, 2011

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 23, 2011 Jul 23, 2011
LATEST

Another suggestion, related to Adam's: did you write <cfcomponent extend="Member"> by mistake instead of <cfcomponent extends="Member">?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources