Search code examples
arraysvariablesscopecoldfusioncfml

CFML - Array and Scope - Object of type class coldfusion.runtime.Struct cannot be used as an array


I would like to use scopes for my array variable names.

This example works.

<cfset person_first_name[1] = "John">
<cfset person_first_name[2] = "Jack">
<cfset x = ArrayLen(person_first_name)>

However, this code occures the following error: "Object of type class coldfusion.runtime.Struct cannot be used as an array"

<cfset person.first_name[1] = "John">
<cfset person.first_name[2] = "Jack">
<cfset x = ArrayLen(person.first_name)>

Isn't it possible to name the variables like that?


Solution

  • Adding a declaration for the array solved the problem. Thanks @SOS.

    <cfset person.first_name = []>