?: operator (the 'Elvis operator') in PHP
I saw this today in some PHP code: $items = $items ?: $this->_handle->result('next', $this->_result, $this); I'm not familiar with the ?: operator being used here. It looks like a ternary operator, but the expression to evaluate to if the predicate is true has been omitted. What does it mean? BalusC It evaluates to the left operand if the left operand is truthy , and the right operand otherwise. In pseudocode, foo = bar ?: baz; roughly resolves to foo = bar ? bar : baz; or if (bar) { foo = bar; } else { foo = baz; } with the difference that bar will only be evaluated once. You can also use