ColdFusion arrays can't use zero as an index.
May 25 |
I should have known better, but I had forgot that you can't use a zero as an index when constructing a ColdFusion array. On this blog, I have 14 different themes, and 39 settings for each theme, and created an array stored in the application scope to store the values in. I wanted to use a zero as an index to identify the name of the theme, and then use 1 through 39 as the theme setting. However, when I tried this approach I received the following error: "A scalar value of type java.lang.String cannot be assigned to a 2-dimensional ColdFusion array."
The problem was solved when I used 1 instead of 0 as the first index. I have always thought that this was odd as assigning a zero index should work. Most other languages default to a zero on the first array item, and still mistakenly assumed that this would work here.
Here was my original code that caused this error:
<!--- Theme --->
<cfset application.arrThemeSettingsFromIniStore[1][0] = "black"><!--- black --->
<!--- Theme variables --->
<cfset application.arrThemeSettingsFromIniStore[1][1] = trim(getSettingsByTheme('black').useCustomTheme)><!--- useCustomTheme --->
more custom theme settings...
The code should not use a zero based index like so:
<!--- Theme --->
<cfset application.arrThemeSettingsFromIniStore[1][1] = "black"><!--- black --->
<!--- Theme variables --->
<cfset application.arrThemeSettingsFromIniStore[1][2] = trim(getSettingsByTheme('black').useCustomTheme)><!--- useCustomTheme --->
more custom theme settings...
Tags
ColdFusion arrayThis entry was posted on May 25, 2019 at 2:31 AM and has received 1783 views.