Bird
0
0

Why does PHP require parameters with default values to be placed after parameters without defaults?

hard📝 Conceptual Q10 of 15
PHP - Functions
Why does PHP require parameters with default values to be placed after parameters without defaults?
ATo avoid ambiguity when calling functions with missing arguments.
BBecause PHP does not support default values at all.
CTo force all parameters to have default values.
DBecause parameters are always passed by reference.
Step-by-Step Solution
Solution:
  1. Step 1: Understand function call ambiguity

    If default parameters came before required ones, PHP wouldn't know which argument matches which parameter when some are missing.
  2. Step 2: Recognize PHP's design choice

    Placing defaults last ensures clear matching of arguments to parameters.
  3. Final Answer:

    To avoid ambiguity when calling functions with missing arguments. -> Option A
  4. Quick Check:

    Parameter order prevents call ambiguity [OK]
Quick Trick: Defaults last prevent confusion in function calls [OK]
Common Mistakes:
  • Thinking PHP disallows default parameters
  • Believing all parameters must have defaults
  • Confusing parameter passing methods

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes