In the context of PHP programming, why is it recommended to store the return value of a method in a variable before using the 'empty' function for evaluation?

When using the 'empty' function in PHP to check if a method's return value is empty, it is recommended to store the return value in a variable first. This is because the 'empty' function can produce unexpected results when used directly on a method call, especially if the method returns a reference. Storing the return value in a variable ensures that the correct value is being evaluated by the 'empty' function.

// Incorrect way - directly using 'empty' on method call
if (empty($object->getMethod())) {
    echo 'Method return value is empty';
}

// Correct way - storing method return value in a variable before using 'empty'
$returnValue = $object->getMethod();
if (empty($returnValue)) {
    echo 'Method return value is empty';
}