I really like the || operator in javascript where we can do standard conditional binding.
var a = 0; var b = 42; var test = a || b || 'default value'; console.log(test);
This is readable and does not take up too many lines.
In PHP, this boolean operator returns booleans:
$a = 0; $b = 42; $test = $a || $b || 'default value'; print_r($test); // bool(true)
Of course, we can do inline binding using tees :
$test = $a ? $a : $b ? $b : 'default'; print_r($test); // int(42)
But this makes the code ambiguous; it is not so easy to read.
So here is my question:
Do you know a good PHP hack to do inline conditional binding?
source share