Watch out for functions that return booleans

A user reported an error to me that I’ve seen a few times recently. His code was doing something like this:

<cfset fleet = arrayAppend(fleet, "Star Destroyer: Wrath of Elmo")>

Later on he did…

<cfloop index="x" from="1" to="#arrayLen(fleet)#">

His error said that he was trying to use a boolean as an array. Where did the error come from? The arrayAppend function, like a few other ColdFusion functions, return true or false, not the changed data structure. Personally I’m not sure why as I don’t know a situation where it would return false.

As another reminder - for functions like these you do not need to actually store the result:

<cfset result = arrayAppend(heroes, "Forge")>

But can instead simply use a shorthand statement:

<cfset arrayAppend(heroes, "Forge")>

Raymond Camden's Picture

About Raymond Camden

Raymond is a developer advocate. He focuses on JavaScript, serverless and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA