Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a difference between declaring a variable in the LOC, VAR, and VARIABLES scopes?

I see all three notations used frequently, and I'm wondering what the differences are between them:

<cfset var foo = "bar" />
<cfset local.foo = "bar" />
<cfset variables.foo = "bar" />
<cfset arguments.foo = "bar" />
like image 442
Mohamad Avatar asked Dec 09 '25 22:12

Mohamad


1 Answers

var and local are the same scope and they are available only to the method/function in which they are declared. The local scope is new to CF 9 before that you used var to create variables that only existed in the method.

Variables is available to the entire cfc or cfm page in which they are declared and any included templates.

arguments is used for arguments passed into a method/function and only exists with in it.

like image 63
Daniel Sellers Avatar answered Dec 12 '25 14:12

Daniel Sellers



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!