Adobe 38043740 - ColdFusion Standard - Mac Development Manual page 74

Developing applications
Hide thumbs Also See for 38043740 - ColdFusion Standard - Mac:
Table of Contents

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
The CFML Programming Language
All functions return values. In the following example, the
function:
<cfset myDate = DateFormat(Now(), "mmmm d, yyyy")>
You can use the values returned by functions directly to create more complex expressions, as in the following example:
Abs(Myvar)/Round(3.14159)
For more information on how to insert functions in expressions, see
Optional function arguments
Some functions take optional arguments after their required arguments. If omitted, all optional arguments default to
a predefined value. For example:
Replace("Eat and Eat", "Eat", "Drink")
Replace("Eat and Eat", "Eat", "Drink", "All")
The difference in the results is because the
of replacement. The default value is "One," which explains why only the first occurrence of "Eat" was replaced with
"Drink" in the first example. In the second example, a fourth argument causes the function to replace all occurrences
of "Eat" with "Drink".
Expression evaluation and functions
It is important to remember that ColdFusion evaluates function attributes as expressions before it executes the
function. As a result, you can use any ColdFusion expression as a function attribute. For example, consider the
following lines:
<cfset firstVariable = "we all need">
<cfset myStringVar = UCase(firstVariable & " more sleep!")>
When ColdFusion server executes the second line, it does the following:
Identifies an expression with a string concatenation.
1
Evaluates the firstVariable variable as the string "we all need".
2
3
Concatenates "we all need" with the string "more sleep!" to get "we all need more sleep!".
Passes the string "we all need more sleep!" to the
4
Executes the
function on the string argument "we all need more sleep!" to get "WE ALL NEED MORE
5
UCase
SLEEP!".
6
Assigns the string value "WE ALL NEED MORE SLEEP!" to the variable myStringVar.
ColdFusion completes steps 1-3 before running the function.
Using multiple assignments in one expression
You can chain assignments to assign the same value to multiple variables in a single statement. This includes chain
assignments for the results of an expression. The following code displays a chain assignment:
a=b=c=d*5
You can use the
operator in multiple assignments, but the variables with this operator must precede all others. For
var
example:
tag sets a variable to the value returned by the
cfset
"Using number
returns "Drink and Eat"
returns "Drink and Drink"
function takes an optional fourth argument that specifies the scope
Replace
function.
UCase
Last updated 1/20/2012
Now
signs" on page 70.
69

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion 9

Table of Contents