Bug with ColdFusion 11's Elvis Operator

Ok, snap quiz time, given the following code, and that url.name exists, will the UDF run?

function getfoo() {
	writeoutput("do you see me?");
	return "foo";	
u2 = encodeForHTML(url.name) ?: getfoo();

Ok, time's up. If you said it wouldn't run, because, of course, it doesn't need to, then you would be wrong. Even when url.name exists, getfoo() is executed. Now, in some ways, this is consistent with cfparam's behavior. But to me, that always made sense. When I see this: <cfparam name="url.name" default="#getfoo()#"> - I always figured the compiler had to run getfoo to get the value to cfparam so cfparam could then work. Maybe you don't agree - and that's cool - but it makes sense to me.

In the case of the Elvis operator though it does not make sense. As an FYI, both Railo and Groovy ignore the right hand side when they don't need it.

Bug: 3818770

Raymond Camden's Picture

About Raymond Camden

Raymond is a developer advocate for Extend by Auth0. He focuses on serverless and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support.

Lafayette, LA https://www.raymondcamden.com