• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Elvis Operator Not Working

Explorer ,
Apr 25, 2022 Apr 25, 2022

Copy link to clipboard

Copied

<cfscript>
    message = [];
    test = true;
    response = test ? ['It is true'] : ['It is not true'];
</cfscript>

CF2021 Throws the following error:

 

ColdFusion was looking at the following text:<p>:</p><p>The CFML compiler was processing:<ul><li>A cfscript tag beginning on line 1, column 2.</ul>

 

Used to work in CF2016 Patch #17

Views

344

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 25, 2022 Apr 25, 2022

Copy link to clipboard

Copied

Before anyone may propose that this is a problem calling for removal of the compiled java class created by his code (which was a problem after a certain recent update, for existing templates that used the elvis operator), that's NOT Jojo's issue here.

 

You can test code in cffiddle.org and see that indeed it will fail. (And no, it will not fail with Lucee, as you can see with trycf.com, which also supports ACF.)

 

The problem is in the use of an array elements on line 4. I agree that it logically should work to use implicit array notation there (just like it would work if you assigned one of those to the first message variable, which seems unneeded in this code).

 

Let's see if Adobe or anyone else may chime in with news on this, or perhaps a workaround.

 

Well, I mean a better workaround than this, which seems obvious enough and works but is likely unsatisfying for your actual need. 🙂

 

 

 

<cfscript>
    message1 = ['It is true'];
    message2 = ['It is not true'];
    test = true;
    response = test ? message1 : message2;
    writedump(response);
</cfscript>

 

 

 

One last thing: I tried your code in cffiddle which ALSO offers running code at CF2016 update 17, and it does not work there. Perhaps you meant it worked BEFORE update 17. (My bad: I had a different error--a missing semi-colon on a writedump line I'd added--which had caused the failure in CF2016 u17, in my test on cffiddle.org.)


/Charlie (troubleshooter, carehart.org)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 25, 2022 Apr 25, 2022

Copy link to clipboard

Copied

@Charlie Arehart 

We're currently on CF2016 update 17 and no, it's not an issue - it currently works - we have plenty of. Yes, we could rewrite them, but there's no easy way of searching for all instances/permutations of the logic. I've already replaced a dozen occurences, I'm not about to go searching for more if I could avoid it.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 25, 2022 Apr 25, 2022

Copy link to clipboard

Copied

Yep, my bad on saying it worked in CF2016 u17. More on that in a moment.

 

And to be clear, I certainly wasn't proposing you should change any code. I said I'd agreed that it should work. I merely mentioned a workaround and that others may try to offer one. But I would agree that past code that worked should continue (unless there's a reason by Adobe that it should no longer be compatible).

 

And really, you should go ahead and file a bug report, at tracker.adobe.com. If you do that, share the link and/or ticket number, so other folks interested can add a vote.

 

Finally, as for my mistake in the last paragraph of my first reply, I did just correct that comment, striking out that last paragraph. As I noted there, the problem was that when I added some additional code (for when things did work elsewhere), I had forgotten the semi-colon. While CF2018 made that optional, CF2016 still requires it. I  failed to notice the error message had changed. 

 

Anyway, I hope the rest of what I added may help folks, in helping you.


/Charlie (troubleshooter, carehart.org)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 26, 2022 Apr 26, 2022

Copy link to clipboard

Copied

No worries @Charlie Arehart - I knew you didn't mean for us to go code hunting 🙂 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 26, 2022 Apr 26, 2022

Copy link to clipboard

Copied

Let's first clear up a misunderstanding. This concerns the ternary operator, not the Elvis operator.

 

In any case, I think it is a bug in CF2021. I have reported it: https://tracker.adobe.com/#/view/CF-4213245 

 

Two workarounds:

 

(1)
<cfscript>
    test=true;
    response = #test# ? ['It is true'] : ['It is not true'];
    writedump(response);
</cfscript>

(2)
<cfset test=true>
<cfset response = (test) ? ['It is true'] : ['It is not true']>
<cfdump var="#response#">

 

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 26, 2022 Apr 26, 2022

Copy link to clipboard

Copied

Good catch, bkbk. Like Jojo, I can get them confused when hurrying. And that's even better on news on your having opened a ticket.

 

And I'd have added a vote, but curiously the vote button isn't visible via mobile (in Chrome on Android). I'd not noticed that before. I wonder if it's because of the attachment offered. Oh well. Hope to do it later on desktop. 

 

Jojo, you'll want to also of course. I realize you've already explained why workarounds will be painful. 


/Charlie (troubleshooter, carehart.org)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 26, 2022 Apr 26, 2022

Copy link to clipboard

Copied

So, @BKBK , what you're saying is that Elvis has left the building?

 

Dave Watts, Eidolon LLC

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 26, 2022 Apr 26, 2022

Copy link to clipboard

Copied

Dave Watts telling dad jokes. What a world, what a world. 🙂


/Charlie (troubleshooter, carehart.org)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 26, 2022 Apr 26, 2022

Copy link to clipboard

Copied

It was right there, waiting for me to say it.

 

Dave Watts, Eidolon LLC

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 26, 2022 Apr 26, 2022

Copy link to clipboard

Copied

Sure. And if the graying beard weren't enough, the fact that you helped write one of the first cf books in '96 means you've more than earned the right to let slip a dad joke once in a while. 🙂 


/Charlie (troubleshooter, carehart.org)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 26, 2022 Apr 26, 2022

Copy link to clipboard

Copied

@BKBK - yep yep, that's correct. 

 

I did upvote as well. We can't upgrade until this is resolved.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Apr 26, 2022 Apr 26, 2022

Copy link to clipboard

Copied

LATEST

Fore reference, here's an observation from Ben Nadal's blog regarding behavior differences between Adobe ColdFusion and Lucee..
https://www.bennadel.com/blog/4231-fundamental-differences-in-elvis-operator-between-adobe-coldfusio...

"the Elvis operator is basically unusable in frameworks like ColdBox (which have to be cross-engine compatible) due to the number of issues that it introduces."

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation