Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7518939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T01:49:23+00:00 2026-05-30T01:49:23+00:00

So, given that I have an instance of this component: foo.cfc <cfcomponent> <cffunction name=locateMe>

  • 0

So, given that I have an instance of this component:

foo.cfc

<cfcomponent>
  <cffunction name="locateMe">
    <cfreturn "I don't know where I live!">
  </cffunction>
</cfcomponent>

And, this other component, fooParent.cfc:

<cfcomponent>
  <cfset this.foo = createObject("component", "foo")>
</cfcomponent>

Let’s say I create instances of “foo” a few different ways:

<cfset myStruct = {}>
<cfset myStruct.foo = createObject("component", "foo")>

<cfset myFoo = createObject("component", "foo")>

<cfset myFooParent = createObject("component", "fooParent")>

<cfoutput>
#myStruct.foo.locateMe()#<br>
#myFoo.locateMe()#<br>
#myFooParent.foo.locateMe()#<br>
</cfoutput>

As expected, this outputs:

I don't know where I live!
I don't know where I live!
I don't know where I live!

What I want to know is, what can I possibly do within foo.cfc that will tell me something (anything!) about the context in which it is being invoked? Since everything ultimately lives in (at least) a scope of some sort, and all scopes are a kind of object, what I’m saying is that I would really like some way to determine the containing object, from within a given instantiated object. Ultimately, some way of building foo.cfc so that something like this could be my output, from my sample snippet above:

I live within a "class coldfusion.runtime.Struct" instance!
I live within a "class coldfusion.runtime.VariableScope" instance!
I live within a "component cfjunk.fooParent" instance!

Where each of those values might be determined by inspecting the result from passing getMetaData the actual containing object reference.

Update As suggested by Micah in the comments, I’ve added the “Java” tag to this, since I suspect he could be correct in that the solution may lie in using Java for introspection.

Update

Rather than leave this as what appears to be a purely-academic discussion, let me explain why I need this.

I’m using CFWheels ORM with includes to get back references to my data like so:

var user = model("User").findOne(where="id=123", include="AuthSource", returnAs="object");

This will return to me an object that I can reference like so:

user.id // property of the "User" model
user.reset() // method on the "User" model
user.AuthSource.id // property of the "AuthSource" model
user.AuthSource.authenticate(password) // method on the "AuthSource" model

Now, within my “AuthSource.authenticate” method, I would like to know about the “User” object that I’m contained within. Otherwise, I will end up having to call the function like this, instead:

user.AuthSource.authenticate(user, password) // note the redundancy in the use of "user"

I should be able to rely on the fact that I’m calling the method on the AuthSource model through the User object and actually read from that object from within that method.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T01:49:24+00:00Added an answer on May 30, 2026 at 1:49 am

    Its been a very long time since i’ve done coldfusion, so forgive my pseudocode, but I think what one normally does in these sort of instances, is have the parent send a copy of itself to the child, when it instantiates the child. This is used in a lot of OOP design patterns where two objects need to communicate with each other both ways, not just the parent calling methods on the child.

    so your child class would be defined as something like this:

    <cfcomponent>
      <cffunction name="init">
         <cfargument name="parentParam" required="yes" type="object">
         <cfset this.parent = parentParam >
          <cfreturn this> 
       </cffuncton>
      <cffunction name="locateMe">
        <cfreturn "I belong to #this.parent.className# !">
      </cffunction>
     <cffunction name="doOtherStuff">
        <cfreturn "I do stuff with my parent: #this.parent.className# !">
      </cffunction>
    </cfcomponent>
    

    and then when you use it…

    <cfset myParent.child = createObject("component", "Object").init(myParent) />
    #myparent.locateMe()#
    #myparent.doOtherStuff()#
    

    parentParam would be a required parameter in a constructor method called “init”, so the child always has a reference to its parent. Then all your methods can make use of this.parent to do stuff with it. In my code example, i do #this.parent.className# but have no idea of coldfusion objects have such a property. Probably you can use reflection or meta-programming of some sort to do the same thing.

    Please note: from what i gather, coldfusion does not have support for constructors built in, so I’m showing you is a community standard best practice from this site:

    http://www.iknowkungfoo.com/blog/index.cfm/2007/8/22/Object-Oriented-Coldfusion–1–Intro-to-Objectcfc

    I’m sorry you are doing colfusion by the way… 😉

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given that I have this resultset structure (superfluous fields have been stripped) Id |
Given that django-nonrel has got JOINs working, does this mean we have M2M fields
datetime.datetime.utcnow() Why does this datetime not have any timezone info given that it is
Given that I have an instance of Fruit with some properties set, and I
I have a component I created that extends Ext.window.Window, I've given it an alias
I have this rather simple question about Scala. Given that i have to following
Given that I have a custom PHP error handler already, does it make sense
Given that I have a table that holds vehicle information and one of those
Given that I have the following WCF service: class LookUpService { public List<County> GetCounties(string
Given that I only have one monitor, what's the best way to debug a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.