Skip to content

Commit d3b5606

Browse files
committed
update null handling with is null info
1 parent aeaff59 commit d3b5606

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

docs/03.reference/01.functions/isnull/_usageNotes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ if ( isNull( local.result ) ) { ... }
2525
if ( isNull( variables.config ) ) { ... }
2626
```
2727

28-
See [[function-structkeyexists]] for additional information regarding null handling in CFML
28+
See [[recipe-null-support]] for more information on null handling in CFML.

docs/recipes/null-support.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,3 +139,32 @@ dump( serializeJSON( s ) ); // {"name":"John","middleName":null}
139139
```
140140

141141
Critical for APIs that expect explicit `null` values rather than missing keys.
142+
143+
## Scoping and isNull()
144+
145+
Always use scoped variable references with [[function-isnull]].
146+
147+
When a variable with a `null` value shares a name with another variable in a scope accesssible via scope cascading, `isNull()` can return unexpected results:
148+
149+
```lucee
150+
name = "default";
151+
152+
function greet( name ) {
153+
if ( isNull( name ) ) {
154+
writeOutput( "Hello stranger" );
155+
} else {
156+
writeOutput( "Hello #name#" );
157+
}
158+
}
159+
160+
greet( javacast( "null", "" ) );
161+
// Outputs: "Hello default" - found the outer variable, not the null argument!
162+
```
163+
164+
Use scoped references to reliably check for `null`:
165+
166+
```lucee
167+
if ( isNull( arguments.name ) ) { ... }
168+
if ( isNull( local.result ) ) { ... }
169+
if ( isNull( variables.config ) ) { ... }
170+
```

0 commit comments

Comments
 (0)