In JavaScript, I can go:
console.log( 'valueA' && 'valueB' ); // 'valueB'
But in PHP:
echo 'a' && 'b'; // 1
As you can see from the above example, the behavior is different. In JS, the value is printed, while in PHP, the boolean is echoed instead.
Is there a PHP operator that will behave like JavaScript's && for short-circuit evaluation? I need the value, not boolean, printed.
In PHP, there is the ?? null coalesce operator, but it doesn't check truthiness, it only checks for null:
echo 'valueA' ?? 'valueB'; // 'valueA'
echo null ?? 'valueB'; // 'valueB', only works as desired with null.
As you can see from the above example, ?? is similar to JavaScript's &&, but it only triggers on null.
Without using if() statements and ternary statements, is there an operator in PHP (doesn't matter which version) that is the equivalent of JavaScript's && for short circuit evaluation?