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:
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.
Step 2: Reason why order matters
Placing parameters with defaults after required ones avoids ambiguity and ensures correct argument matching.
Final Answer:
To avoid ambiguity in argument assignment during function calls -> Option D
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
Master "Functions" in PHP
9 interactive learning modes - each teaches the same concept differently