Implicit array/struct and function calls

I'm thinking this is something folks have blogged about before, but I just ran into it today. When using array and struct implicit creation, you cannot use the syntax directly in a udf/method call. Let me explain. Consider this example:

<cfset z = {name='r',age=34}> <cfset somefunc(data=z)>

In this example I use shorthand notation to creation a structure. I then pass it to somefunc as an argument named data. This works just fine. But this version, which should be the same, will give you a syntax error:

<cfset somefunc(data={name='r',age=34})>

I also tried the simpler form:

<cfset somefunc({name='r',age=34})>

Which also failed. It looks like you can only use the implicit creation in cfset statements. (Which is certainly ok, I'm just happy we have this shortcut!)

Raymond Camden's Picture

About Raymond Camden

Raymond is a developer advocate for HERE Technologies. 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