Are there any best practices or design patterns recommended for handling functions that return multiple types of values in PHP?

When a function needs to return multiple types of values in PHP, it can be challenging to handle the different types of return values in the calling code. One common approach is to return an array with keys representing the different types of values. Another option is to use a custom class or data structure to encapsulate the return values. This can make the code more readable and maintainable.

// Example using an array to return multiple types of values
function getMultipleValues(): array {
    // Perform some logic to determine the values
    $value1 = 'string value';
    $value2 = 123;
    
    return ['value1' => $value1, 'value2' => $value2];
}

// Calling the function and accessing the return values
$result = getMultipleValues();
echo $result['value1']; // Output: string value
echo $result['value2']; // Output: 123