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 6637073
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:16:03+00:00 2026-05-25T23:16:03+00:00

I’m having an issue with a Coldfusion component that I’m building. Well, I’m not

  • 0

I’m having an issue with a Coldfusion component that I’m building. Well, I’m not really sure if it’s a problem or how things are supposed work, but it seems strange. First, I set up arguments for the init function of my component and invoke the component. But if I change one of the arguments after I invoke, it also changes the values held in the component. Is this correct?

I’m not sure if I’m explaining this very well. Here’s some pseudo-code:

<cfset fruit = [] />
<cfset fruit[1] = {
    id = 1,
    name = "apple"
} />
<cfset fruit[2] = {
    id = 2,
    name = "orange"
} />

<cfset args = {
    title = "Fruit",
    data = fruit
} />

<cfinvoke component="test" method="init" returnvariable="test" argumentcollection=#args# />

<cfset fruit[2].name = "banana" />

The init function stores the title and data arguments in the component’s variables scope.

Now, if I output the data from the test object, I get apple and banana. But I was expecting the component to retain the data that it received during the invoke.

Let me know if I need to clarify anything. Thanks for any help!

  • 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-25T23:16:03+00:00Added an answer on May 25, 2026 at 11:16 pm

    I’m not really sure if it’s a problem or how things are supposed work,

    Yes, that is how your current code is supposed to work. Whether that is how you want it to behave is a different question ..

    Most complex objects (structures, components, etectera) are passed by reference. Meaning you are essentially just storing a pointer to the object, not the actual values. So you will always see any changes made to the underlying object. That is why the output from test changes.

    Arrays are an exception. They are usually (though not always) passed by value. Meaning you have an independent copy that will not reflect any changes made to the original object.

    Your example is interesting because it contains both. Changes to your nested structures (name=orange => name=banana) are visible in the component because the structures are passed by reference. But the parent array is not. So you could clear fruit and it would have no effect on the component.

    Example:

    <cfset fruit[2].name = "bananna" />
    
    <!--- both dumps will show "bananna" --->
    <cfdump var="#fruit#" label="Fruit Before" />
    <cfdump var="#test.getDataArray()#" label="Test.Data Before" />
    
    <cfset arrayClear(fruit) />
    
    <!--- fruit is empty and the component array is not --->
    <cfdump var="#fruit#" label="Fruit After" /> 
    <cfdump var="#test.getDataArray()#" label="Test.Data After" /> 
    

    Test:

    <cfcomponent>
    
      <cffunction name="init" returntype="any" ...>
         <cfargument name="title" type="string" required="true" />
         <cfargument name="data" type="array" required="true" />
         <cfset variables.title = arguments.title />
         <cfset variables.data = arguments.data />
         <cfreturn this />   
      </cffunction>
    
      <cffunction name="getDataArray" returntype="array">
         <cfreturn variables.data />
      </cffunction>
    
    </cfcomponent>
    

    Now, if I output the data from the test object, I get apple and banana.

    Right. That is to be expected because structures are passed by reference. If you want the component to maintain a independent copy, you need to duplicate() (ie deep copy) the data element inside init().

       <cfset variables.data = duplicate(arguments.data) />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I need a function that will clean a strings' special characters. I do NOT
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I am currently running into a problem where an element is coming back from
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm having trouble keeping the paragraph square between the quote marks. In firefox the

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.