Whatever message this page gives is out now! Go check it out!
<cfscript>
variables.myVar.a.b = "apple";
writeDump( variables[ "myVar.a.b" ] );
</cfscript>
<cfset myVar.a.b = "This is a test">
<cfdump var=#Client.myVar.a.b#>
<cfscript>
Request["Another.Variable.With.Periods"] = "Test variable";
writeOutput("My.Variable.With.Periods is: #My.Variable.With.Periods#
Request.Another.Variable.With.Periods is:
#Request.Another.Variable.With.Periods#");
</cfscript>
<cfset Cookie.User.Preferences.CreditCard="Discover">
?. operator only protects the specific access it precedes. A key accessed after a hook, without its own ?., is not guarded — it remains the developer's responsibility and can still throw an exception. Similarly, once a hooked expression resolves to a real (non-null) value, ColdFusion falls back to standard dot-notation rules for anything chained afterward, which can throw if the value's type does not support the next access.| Expression | Behavior |
|---|---|
a?.b | If a is undefined/null, the whole expression evaluates to null. If a exists but b is missing, the result is also null — the terminal key after the hook is guarded too. No exception is thrown in either case. |
a.b?.c | The hook guards the entire left-hand side, a.b. If any part of the left side is missing or null (a missing, b missing, or a.b evaluates to null), the result is null, not an exception. If a.b is a struct and c is missing, the result is also null. Exception: if a.b resolves to a real, non-null scalar value (for example, the string "hello"), then ?.c throws a ScopeCastException ("cannot dereference a scalar as a structure"). This happens because ColdFusion's internal (Map) coercion runs before the safe navigation check. |
a?.b?.c | Fully chained hooks. A null or missing value at any hooked link short-circuits the rest of the chain, and the whole expression returns null. |
a()?.b | If the method call a() returns null, accessing .b afterward returns null instead of throwing, because the hook is applied to the result of the call. |
a.b.c()?.d | If c() returns a non-null value that .d cannot be applied to, an exception is thrown. If c() returns null, ?.d returns null. If an earlier, unhooked part of the expression (a or b) is null, the whole expression returns null. |
?., is unguarded and can still throw a runtime exception (for example, ScopeCastException) if the resolved value is an incompatible type.