Bird
0
0

Why does PHP allow method overriding but not method overloading (same method name, different parameters)?

hard📝 Conceptual Q10 of 15
PHP - Inheritance and Polymorphism
Why does PHP allow method overriding but not method overloading (same method name, different parameters)?
AOverriding requires different method names
BPHP resolves methods by name only, ignoring parameters at runtime
COverloading is done automatically by PHP using magic methods
DPHP supports both overriding and overloading fully
Step-by-Step Solution
Solution:
  1. Step 1: Understand PHP method resolution

    PHP identifies methods by name only, not by parameter types or counts.
  2. Step 2: Effect on overloading

    Because of this, PHP does not support traditional method overloading (same name, different parameters).
  3. Final Answer:

    PHP resolves methods by name only, ignoring parameters at runtime -> Option B
  4. Quick Check:

    Method resolution = name only, no overloading [OK]
Quick Trick: PHP methods identified by name only, no overloading [OK]
Common Mistakes:
  • Thinking PHP supports overloading like Java
  • Confusing overriding with overloading
  • Assuming magic methods replace overloading fully

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes