What are the best practices for type checking in PHP, especially for primitive data types?

When working with primitive data types in PHP, it is important to ensure that the correct type of data is being used to prevent unexpected errors or behavior in your code. One way to do this is by using type hinting in function parameters to specify the expected data type. Additionally, you can use functions like is_int(), is_string(), is_float(), etc., to check the type of a variable before using it in your code.

function addNumbers(int $num1, int $num2) {
    return $num1 + $num2;
}

$number1 = 5;
$number2 = "10";

if (is_int($number1) && is_int($number2)) {
    echo addNumbers($number1, $number2);
} else {
    echo "Invalid input. Please provide two integers.";
}