What are the best practices for handling return values in PHP functions, and how should they be implemented in the context of the zinsen function?

When handling return values in PHP functions, it is best practice to always check for errors and handle them appropriately. In the context of the zinsen function, you should ensure that the function returns a valid value and handle any potential errors or exceptions that may occur. This can be done by using conditional statements to check the return value and handle it accordingly.

function zinsen($kapital, $zinssatz, $jahre) {
    $zinsen = $kapital * $zinssatz * $jahre;
    
    if($zinsen < 0) {
        throw new Exception('Error: Invalid calculation result');
    }
    
    return $zinsen;
}

try {
    $kapital = 1000;
    $zinssatz = 0.05;
    $jahre = 5;
    
    $zinsen = zinsen($kapital, $zinssatz, $jahre);
    echo "Zinsen: $zinsen";
} catch (Exception $e) {
    echo 'Error: ' . $e->getMessage();
}