Skip to content

Commit aeaff59

Browse files
committed
add usage notes for isNull
1 parent 2744044 commit aeaff59

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
Always use scoped variable references with `isNull()`.
2+
3+
When a null argument shares a name with an outer-scoped variable, `isNull()` can return the wrong result / unexpected due to scope cascading:
4+
5+
```lucee
6+
name = "default";
7+
8+
function greet( name ) {
9+
if ( isNull( name ) ) {
10+
writeOutput( "Hello stranger" );
11+
} else {
12+
writeOutput( "Hello #name#" );
13+
}
14+
}
15+
16+
greet( javacast( "null", "" ) );
17+
// Outputs: "Hello default" - found the outer variable, not the null argument!
18+
```
19+
20+
Use scoped references to reliably check for null:
21+
22+
```lucee
23+
if ( isNull( arguments.name ) ) { ... }
24+
if ( isNull( local.result ) ) { ... }
25+
if ( isNull( variables.config ) ) { ... }
26+
```
27+
28+
See [[function-structkeyexists]] for additional information regarding null handling in CFML

0 commit comments

Comments
 (0)