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
– Maniero
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 calledweighting operator
– Guilherme Nascimento
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..
– Guilherme Nascimento
@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 buildingExp ? 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.– Bacco
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
@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.
– Wallace Maxters
@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.
– Piovezan