Bird
0
0

Why must parameters with default values come after parameters without default values in PHP function definitions?

hard📝 Conceptual Q10 of 15
PHP - Functions
Why must parameters with default values come after parameters without default values in PHP function definitions?
ATo allow parameters to be passed by reference
BBecause PHP does not allow default values at all
CTo improve function execution speed
DTo avoid ambiguity in argument assignment during function calls
Step-by-Step Solution
Solution:
  1. Step 1: Understand parameter assignment rules

    When calling a function, PHP assigns arguments to parameters in order. If default parameters come first, it causes confusion about which argument matches which parameter.
  2. Step 2: Reason why order matters

    Placing parameters with defaults after required ones avoids ambiguity and ensures correct argument matching.
  3. Final Answer:

    To avoid ambiguity in argument assignment during function calls -> Option D
  4. Quick Check:

    Default parameters last prevent ambiguity [OK]
Quick Trick: Default parameters last to keep argument matching clear [OK]
Common Mistakes:
  • Thinking order affects speed
  • Believing PHP disallows default values
  • Confusing default values with references

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes