Why is PHP not able to declare types securely?
PHP is not able to declare types securely because it is a dynamically typed language, meaning variable types are determined at runtime, leading to potential type-related errors. One way to address this issue is by using PHP 7's type declarations feature, which allows developers to specify the expected data type for function parameters and return values, enhancing code reliability and readability.
function addNumbers(int $num1, int $num2): int {
return $num1 + $num2;
}
echo addNumbers(5, 10); // Output: 15