Skip to content

Commit a07d06d

Browse files
committed
cross ref structkeyexists with operators
1 parent 96aea88 commit a07d06d

File tree

2 files changed

+34
-1
lines changed
  • docs
    • 03.reference/01.functions/structkeyexists
    • 04.guides/11.developing-with-lucee-server/03.operators

2 files changed

+34
-1
lines changed

docs/03.reference/01.functions/structkeyexists/function.md

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,36 @@ Determines whether a specific key is present in a structure.
1313

1414
In CFML, by default, this will return `false` for any keys with a `null` value, however, if Full Null Support is enabled, it will return `true`.
1515

16-
[[null_support]]
16+
[[null_support]]
17+
18+
## See Also: Elvis and Safe Navigation Operators
19+
20+
For many common use cases, consider using these more concise alternatives:
21+
22+
- **Elvis operator (`?:`)** - Returns a default value if the left side is null or undefined:
23+
24+
```lucee
25+
// Instead of:
26+
if ( structKeyExists( args, "name" ) ) {
27+
result = args.name;
28+
} else {
29+
result = "default";
30+
}
31+
// Use:
32+
result = args.name ?: "default";
33+
```
34+
35+
- **Safe navigation operator (`?.`)** - Safely traverse nested properties, combine with elvis for a default value:
36+
37+
```lucee
38+
// Instead of:
39+
if ( structKeyExists( user, "address" ) && structKeyExists( user.address, "city" ) ) {
40+
city = user.address.city;
41+
} else {
42+
city = "Unknown";
43+
}
44+
// Use:
45+
city = user?.address?.city ?: "Unknown";
46+
```
47+
48+
[[operators]]

docs/04.guides/11.developing-with-lucee-server/03.operators/page.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ id: operators
44
related:
55
- function-max
66
- function-min
7+
- function-structkeyexists
78
categories:
89
- core
910
- math

0 commit comments

Comments
 (0)