Last updated:

Get Your Site Submitted for Free in the World's Largest B2B Directory!

Email Address:
* URL:
*
*Indicates Mandatory Field

Terms & Conditions

Submit Your Site To ItalianWebSearch

DevWebProIT
FlashNewz
DevWebPro





Object Of Type Class.lang.Boolean Cannot Be Used As An Array

By Raymond Camden
Expert Author
Article Date: 2008-01-02

Darren asks: is there anything wrong with this function because when i invoke it i get a weird error i don't understand which is "Object of type class.lang.Boolean cannot be used as an array"...

all i'm doing is query the db and compiling it into a 1 dimensional array. heres the function

(some stuff deleted)
<cfquery name="getExtraImages" datasource="#request.dsn#"> SELECT * FROM extraimages </cfquery>

<cfset imageArray = arrayNew(1)>

<cfloop query="getExtraImages" startrow="1" endrow="#getExtraImages.recordcount#">
<cfset imageArray = arrayAppend(imageArray, "#extraImagePath#")>
</cfloop>


This is a simple problem, and one I see often. I'm pretty sure I answered this question before on the blog before, but as I said - it shows up often.

The problem is the arrayAppend function. You would think that it takes an array, a value to add to it, and returns the new (larger) array.


Instead, the function changes the array you pass to it directly and returns true or false.

Now - I've never seen arrayAppend return false before, so it isn't something you have to worry about checking, but you do need to ensure you use it the right way. I'd change his line above to:

<cfset arrayAppend(imageArray, extraImagePath)>

Note that I removed the unnecessary pound signs as well. If that line confuses you, you can think of it like running a function and assigning to nothing. Imagine this:

<cfset temp = arrayAppend(imageArray, extraImagePath)>

Now imagine you don't need temp. That's where the shorter syntax is useful.

Comments

About the Author:
Raymond Camden, ray@camdenfamily.com
http://ray.camdenfamily.com

Raymond Camden is Vice President of Technology for roundpeg, Inc. A long time ColdFusion user, Raymond has worked on numerous ColdFusion books and is the creator of many of the most popular ColdFusion community web sites. He is an Adobe Community Expert, user group manager, and the proud father of three little bundles of joy.


Newsletter Archive | Article Archive | Submit Article | Advertising Information | About Us | Contact

DevWebProItaly is an iEntry.com publication
© iEntry Inc. All Rights Reserved Privacy Policy Legal

Click Here to Return to the Home Page