Bird
0
0

Why does PHP allow union types like int|float for function parameters starting PHP 8.0?

hard📝 Conceptual Q10 of 15
PHP - Functions
Why does PHP allow union types like int|float for function parameters starting PHP 8.0?
ATo deprecate scalar type declarations.
BTo enforce strict typing by limiting to one type only.
CTo allow parameters to accept multiple specified types for flexibility.
DTo automatically convert all types to string.
Step-by-Step Solution
Solution:
  1. Step 1: Understand union types purpose

    Union types allow a parameter to accept values of multiple specified types.
  2. Step 2: Analyze options

    To allow parameters to accept multiple specified types for flexibility. correctly states union types increase flexibility. Others are incorrect or unrelated.
  3. Final Answer:

    To allow parameters to accept multiple specified types for flexibility. -> Option C
  4. Quick Check:

    Union types = multiple allowed types [OK]
Quick Trick: Union types increase parameter flexibility [OK]
Common Mistakes:
  • Thinking union types enforce single type
  • Believing union types convert to string
  • Confusing union types with deprecation

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes