Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Array parameter, empty by default

I want to pass an optional array parameter to a function. If the parameter is not provided, the array should be empty. I tried the following:

<cfargument name="time_blocks" type="array" required="false" default="[]">

But I get the following error:

invalid call of the function CreateRateBlock
14th Argument (time_blocks) is of invalid type, can't cast String [] to a value of type [array]

I also tried this:

<cfargument name="time_blocks" type="array" required="false" default="">

In this case, the error is almost the same:

invalid call of the function CreateRateBlock
14th Argument (time_blocks) is of invalid type, can't cast String [] to a value of type [array]

I also tried removing the default attribute, but in that case the value of time_blocks is null. What am I doing wrong?

like image 738
Michael Avatar asked Jan 07 '15 20:01

Michael


2 Answers

[] does not work because it is just a string of 2 chars "[]".

#[]# technically should work, but older CF is not smart enough. So use:

<cfargument name="time_blocks" type="array" required="false" default="#arrayNew(1)#">
like image 97
Henry Avatar answered Sep 27 '22 23:09

Henry


Change [] to #[]#. You're currently trying to give it the literal value "[]".

like image 28
Regular Jo Avatar answered Sep 28 '22 01:09

Regular Jo