I asked Omitting the second part of the ternary operator when I was dead tired, and made a mistake that changed the nature of the question.

I still want to know the answer to the "real" question, but the "wrong" question generated quite a bit of discussion. Apparently a number of people found it interesting (they seem to have been unaware of the feature under discussion).

I want to re-ask the "real" question. What to do with the "wrong" one?

  • Doesn't this answer "Expression expr1 ?: expr3 returns expr1 if expr1 evaluates to TRUE, and expr3 otherwise." answer your real question? – Mat Nov 12 '11 at 8:47
  • @Mat, I interpreted it as a question of precedence between the assignment and ternary operators, rather than the behaviour of just the ternary operator. But then I'm not familiar with PHP and may have attached some C semantics where they don't belong. – Brian Reichle Nov 12 '11 at 10:39
  • @BrianReichle: If having an empty expression in the second "part" of the ternary changes precedence rules, I'm staying even farther away from PHP than I already am :) – Mat Nov 12 '11 at 10:52
  • The question has more to do with the fact that you have to use isset() for a potentially non-existant property. Like I said, I messed the question up, but the question I asked has value of it's own. – Sinthia V Nov 12 '11 at 17:39

Leave the question you originally asked - you've made a useful contribution to the community by asking it - hence the upvotes on your question and on the top answer.

Now, ask as a new question (on SO), the question you really meant to ask. Link to the old one too, if they're directly related, and mention the solution from top answer, if it's relevant.

Oh, and consider accepting as an answer, one of the answers on your original question, if you feel that it has answered the question as you asked it (rather than as you intended to ask it)

| improve this answer | |

It seems that the question that you meant to ask was "If it evaluates to true, will $att['menu text'] be set to isset($attrib_in['i_menu_text']) or $this->getID()?" to which the answer given from Keith Thompson still applies. When isset($attrib_in['i_menu_text']) evaluates to TRUE, the value assigned to the variable is TRUE.

If that is the question you wanted to ask, there is no need to ask a new question, because the answer has been already given. If you ask the question I suppose you wanted to ask, the question would be closed as duplicate.

| improve this answer | |

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .