Why is the operator "?:" called Elvis Operator?

Asked

Viewed 900 times

2

In PHP, I usually use some expressions to simplify the declaration of a variable conditionally, via the operator ?:.

Example:

function testing($usuario = null) {
    $usuario ?: $usuario = request()->user();
}

I saw that the operator ?: is called Elvis Operator, across of that answer.

But why does this operator have that name?

  • https://answall.com/q/44133/101

  • 1

    To me it seems a person, 2 eyes and the hand in the mouth or chin ?: https://i.stack.Imgur.com/X2x2q.jpg --- could be called weighting operator

  • 1

    If I’m not mistaken Elvis Operator is when it is using as "Binary Operator", already when it is used as ternary is called "Ternary Operator", so I think it depends on the language if it will be called Elvis Operator or Ternary Operator. In PHP it is called https://www.php.net/manual/en/language.operators.comparison.php#language.operators.comparison..

  • 5

    @Guilhermenascimento Elvis is always a binary operator, and spelled exactly ?:. The Conditional Operator (ternary is a feature of it, not the name), is not the operator ?: but a building Exp ? seV : seF . "Almost by chance" both use the same characters, but each with a distinct meaning. In the case of the Conditional Operator , ? is the operator and the : a delimiter). It must have been purposeful the similarity to associate to a similar behavior, but still are distinct functionalities.

  • 4

    What kind of reliable source do you expect? This nickname is part of popular culture, so wikipedia (article cited in the current answer) would be one of the best sources. I find it difficult that there are academic studies on this in the area of computer science or etymology.

  • @bfavaretto then we can leave the reward to reward the existing answer. My idea was to put some more doubts, but I preferred not to do it so as not to harm the answer already given.

  • @Wallacemaxters Just my 2 cents, if you want to make a future response with a reward, be my guest. Mine I do not know if it deserves because it was given in a hurry and I have no practice to answer other questions, but nothing against someone answering even taking advantage of information from my reply. You can turn it into wiki too, I don’t know if I lose the points (if I lose patience too, it only gives a little help because it came a lot and without much effort... as they say, it comes easy, it goes easy :D). You just have to see if you can leave all your doubts in one question or separate.

Show 2 more comments

1 answer

10


  • 1

    Great name by the way kkkkkkkkkk

Browser other questions tagged

You are not signed in. Login or sign up in order to post.