How can including a function within an if statement lead to errors in PHP?

Including a function within an if statement can lead to errors in PHP if the function has side effects or returns unexpected values. To avoid this, it's best to assign the function result to a variable outside of the if statement and then use that variable in the condition. This ensures that the function is only called once and its result is predictable.

// Assign the function result to a variable
$result = someFunction();

// Use the variable in the if statement
if ($result == true) {
    // Code to execute if the condition is true
}