coldfusioncoldfusion-9cffunction

Difference between cfparam and cfargument in a coldfusion function?


What's the difference between these two blocks of code, when called right after a cffunction tag:

<cfparam name="bork_bork_bork" default="false">

<cfargument name="bork_bork_bork" required="false" default="false">

Solution

  • <cfparam>, when used with the default attribute, will ensure that a variable exists. Because there is no scope specified, bork_bork_bork is being put in to the Variables scope.

    <cfargument> is used to pass an arguments to a function. These values are stored in the Arguments scope. You would access the value using arguments.bork_bork_bork.

    Note that arguments.bork_bork_bork and bork_bork_bork are not the same. The scope of arguments is only within the function, the other is being stored in the Variables scope and will be valid anywhere on the page (though I would not recommend coding it that way.)