tracker issue : CF-4199049

select a category, or use search below
(searches all categories and all time range)

Null coalescing operator

| View in Tracker

Status/Resolution/Reason: Needs Review//Investigate

Reporter/Name(from Bugbase): Bryan Henderson / Bryan Henderson ()

Created: 07/11/2017

Components: Language

Versions: 2016

Failure Type: Others

Found In Build/Fixed In Build: /

Priority/Frequency: Normal /

Locale/System: / Platforms All

Vote Count: 3

Catch undefined values and return a default.  Suggested operator syntax: ?? (double question mark)

A new operator that works as the Elvis operator (?:) originally worked (see CF-3589888) before it was rendered useless (see CF-4028653) for null coalescence by making it function as a binary equivalent to the ternary conditional operator (? :) due to its equating null/undefined variables with variables defined with falsey values.

Specifically, a defined variable with falsy values MUST NOT return the default, or right expression, rather it should return the value of the variable as it is defined:

myVar1 = 0;
test1 = myVar1 ?? 1;
// should result in test1 = 0

myVar2 = false;
test2 = myVar2 ?? true;
// should result in test2 = false

myVar3 = "no";
test3 = myVar3 ?? "yes";
// should result in test3 = "no"

test4 = myUndefinedVar ?? "default";
// should result in test4 = "default"



+1 - Thought I'd already voted. Voting now for sure :)
Vote by Aaron N.
513 | February 15, 2018 04:08:34 AM GMT
I appreciate this ticket, but the elvis operator was already introduced as a null coalescing operator before it was ruined by an attempt to retroactively make it behave as a shortened ternary-- something that CFML is not capable of actually doing since CFML lacks the proper truthy/falsey constructs that language like JavaScript and Groovy have. Instead of making elvis be a hacked-up combination of two things, it needs to be fixed to be a proper null coalescing operator and then this ticket won't be needed. We tried to start using the elvis operator in ColdBox 5 since we dropped CF10 support, but it is so inconsistent we could not use it.
Comment by Bradley W.
29273 | July 11, 2018 05:34:42 AM GMT