Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ARGUMENT scope not taking precedence over VARIABLE scope in ColdFusion?

As per the CF documentation:

ARGUMENT scope takes precedence over VARIABLE scope

I tried this code.

<cfset fun(25)>
<cffunction name="fun">
  <cfargument name="roll" >
  <cfset roll = 60>
  <cfdump var="#roll#">
</cffunction>

I expect the output to be 25, but its 60. I cannot understand why the ARGUMENT scope is not taking precedence over VARIABLE scope? Or am I missing something?

like image 550
user3427540 Avatar asked Mar 24 '26 19:03

user3427540


1 Answers

You've just updated arguments.roll to 60. If you want a local function variable that's not going to be overwritten by the argument of the same name, assign it to the local scope:

<cfset local.roll = 60>
<cfdump var="#roll#">  // 25, as arguments scope takes precedence
<cfdump var="#local.roll#"> // 60
<cfdump var="#arguments#">  // 25
like image 122
duncan Avatar answered Mar 27 '26 23:03

duncan



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!