What are the potential pitfalls of using logical operators like && for variable assignments in PHP?

Using logical operators like && for variable assignments in PHP can lead to unexpected behavior because they are meant for conditional statements, not assignments. This can result in unintended side effects or errors in your code. To avoid this issue, it is recommended to use a separate if statement for conditional logic and then assign the variable accordingly.

// Incorrect way of using logical operators for variable assignments
$var = ($condition1 && $condition2) ? 'value1' : 'value2';

// Correct way of using if statement for conditional logic and variable assignment
if ($condition1 && $condition2) {
    $var = 'value1';
} else {
    $var = 'value2';
}