github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/gen/expr/elvis_op_doc.yaml (about) 1 - DocumentID: elvis 2 Title: >- 3 `?:` Elvis Operator 4 CategoryID: parser 5 Summary: >- 6 Returns the right operand if the left operand is falsy (expression) 7 Description: |- 8 The Elvis Operator is a little like a conditional where the result of the 9 operation is the first non-falsy value from left to right. 10 11 A falsy value is any of the following: 12 13 * an unset / undefined variable 14 * any value with a `null` data type 15 * a `str` or generic with the value `false`, `null`, `0`, `no`, `off`, `fail`, 16 `failed`, or `disabled` 17 * a number (`num`, `float` or `int`) with the value `0` 18 * an empty object or zero length array 19 * and, of course, a boolean with the value `false` 20 Examples: |- 21 **Assign a variable with a default value:** 22 23 ``` 24 » $foo = $bar ?: "baz" 25 ``` 26 27 If `$bar` is falsy, then the value of `$foo` will be **"baz"**. 28 29 **Multiple elvis operators:** 30 31 ``` 32 » $unset_variable ?: null ?: false ?: "foobar" 33 foobar 34 ``` 35 Detail: |- 36 ### Whats in a name? 37 38 [Wikipedia](https://en.wikipedia.org/wiki/Elvis_operator) explains this best 39 where it says: 40 41 > The name "Elvis operator" refers to the fact that when its common notation, 42 > `?:`, is viewed sideways, it resembles an emoticon of Elvis Presley with his 43 > signature hairstyle. 44 Related: 45 - expr 46 - null-coalescing 47 - pipe-err 48 - pipeline 49 - schedulers 50 - out 51 - err 52 - try 53 - trypipe 54 - logical-and 55 - logical-or 56 - "null"