What are some common pitfalls when trying to create complex mathematical functions in PHP?

One common pitfall when creating complex mathematical functions in PHP is not handling edge cases or unexpected inputs properly, which can lead to errors or incorrect results. To avoid this, it's important to thoroughly test the function with various inputs and ensure that it can handle all possible scenarios.

function complexMathFunction($x, $y) {
    // Check if inputs are valid
    if (!is_numeric($x) || !is_numeric($y)) {
        throw new InvalidArgumentException('Inputs must be numeric');
    }
    
    // Perform complex mathematical operations
    $result = $x * $y + pow($x, 2) - sqrt($y);
    
    return $result;
}

// Test the function with different inputs
try {
    echo complexMathFunction(5, 2); // Output: 33.47213595499958
    echo complexMathFunction('abc', 2); // Throws InvalidArgumentException
} catch (InvalidArgumentException $e) {
    echo 'Error: ' . $e->getMessage();
}