Web Development

General discussion


coldfusion array error

By ndd ·
Help please

getting the following error:

Object of type class java.lang.String cannot be used as an array

from following code:

<!--- values being passed from the add to cart form

<!--- set the default for new session --->
<cfparam name="session.cart" default="arrayNew()">

<!--- append new element to array --->
<cfset session.cart = arrayAppend( session.cart, structNew() )>

<!--- set array position --->
<cfset thisCartItem = arrayLen( session.cart )>

<!--- populat the new structure --->
<cfset session.cart[thisCartItem].myItem = form.myItem>
<cfset session.cart[thisCartItem].myQty = form.myQty>
<cfset session.cart[thisCartItem].shipping = form.shipping>
<cfset session.cart[thisCartItem].mysku = form.mysku>

This conversation is currently closed to new comments.

Thread display: Collapse - | Expand +

All Comments

Collapse -

by alexeiramone In reply to coldfusion array error

Try this:

1) Provide a type in <cfparam>, it this case, array and try not to set the default to arraynew(), leave this and define the array in further cfset.

2) Try not to add the struct directly in arrayappend like you did in arrayAppend(session.cart,structNew()). Try something like this: arrayAppend(session.cart,uSomething) and after, define it as a struct.

Related Discussions

Related Forums