3

I start this year with a big question. When I do

myName = "Henry";
myCustomFunction( [ myName, "Thierry" ] );

It throws an error like myName is undefined. Why?

I can resolve this by doing

myName = "Henry";
aMyArrayArgument = [ myName, "Thierry" ];
myCustomFunction( aMyArrayArgument );

But still, I want to know why Coldfusion don't allow to pass [ myName, "Thierry" ] in arguments?

I use Framework One (FW/1) if it can help.

Thank you!

James A Mohler
  • 11,060
  • 15
  • 46
  • 72
Adysone
  • 121
  • 1
  • 8
  • 7
    I suspect it related to your function definition. What is the signature of `myCustomFunction`? Also, what is the exact error message? – Leigh Jan 07 '13 at 16:40
  • 1
    I'll echo what the others have said. The code you quote is fine. It's some other code that is giving you the error. Can I recommend you look at the error with Robust Exception Handling switched on, it'll give you the exact error message, and the line it occurs on. Then you can provide us with that, instead of something vague like "It throws an error like myName is undefined". Don't give us what the error is *like*, give us the exact error, and the exact code that causes the error. – Adam Cameron Jan 07 '13 at 21:47
  • This sounds like a variant of bug [#3482734](https://bugbase.adobe.com/index.cfm?event=bug&id=3482734) - I'm guessing the actual code is inside a block and uses named arguments. – Peter Boughton Jul 17 '13 at 17:13

2 Answers2

1

If I do this:

 <cffunction name="xx" returntype="void">
     <cfargument name="x" type="array">
     <cfdump var="#arguments.x#">
 </cffunction>

 <cfset myname = "dan">
 <cfset xx([myname, 'bracuk']) >

The code runs without error and I see the dump. There must be something else going on with your code.

Dan Bracuk
  • 20,699
  • 4
  • 26
  • 43
1

If your actual code looks more like this:

if (something)
{
    myName = "Henry";
    myCustomFunction( argname=[ myName, "Thierry" ] );
}

Then it's because the literal struct and array notation in CF is very badly written and buggy.

If you can confirm the circumstances it breaks, raise an issue with Adobe (there are several issues relating to this already; you may or not feel like checking for duplicates).

Peter Boughton
  • 110,170
  • 32
  • 120
  • 176