Bird
0
0

What issue arises from this PHP function?

medium📝 Debug Q6 of 15
PHP - Type Handling
What issue arises from this PHP function?
function addFive(int $num) {
return $num + 'five';
}
APHP automatically converts 'five' to 5 without issues
BThe function lacks a return type declaration
CThe parameter should be a string, not an integer
DAdding an integer to a non-numeric string causes a type error
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the operation

    Adding an integer to a non-numeric string triggers a warning or error.
  2. Step 2: Understand PHP behavior

    PHP cannot convert 'five' to a number automatically.
  3. Final Answer:

    Adding an integer to a non-numeric string causes a type error -> Option D
  4. Quick Check:

    Non-numeric strings can't be used in arithmetic [OK]
Quick Trick: Non-numeric strings cause errors in math [OK]
Common Mistakes:
  • Assuming PHP converts 'five' to 5 automatically
  • Ignoring missing return type declaration
  • Thinking parameter type is incorrect

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes