What are the potential pitfalls of directly outputting values with echo in PHP functions?

Directly outputting values with echo in PHP functions can lead to unexpected results, such as outputting content before headers are sent or interfering with other functions that expect to return values instead of directly outputting them. To avoid these pitfalls, it is recommended to store the output in a variable within the function and return the variable instead.

function getValue() {
    $value = "Hello, World!";
    return $value;
}

echo getValue();