File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed
docs/03.reference/01.functions/isnull Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments