Bird
0
0

Identify the error in this PHP function:

medium📝 Debug Q6 of 15
PHP - Functions
Identify the error in this PHP function:
function calculate($a = 10, $b) {
  return $a + $b;
}
AFunction must return a string, not a number.
BFunction name is invalid.
CParameters must be separated by semicolons.
DDefault parameter cannot precede a non-default parameter.
Step-by-Step Solution
Solution:
  1. Step 1: Check parameter order

    Parameter with default ($a=10) comes before non-default ($b), which is invalid in PHP.
  2. Step 2: Confirm PHP syntax rules

    All parameters with defaults must be after parameters without defaults.
  3. Final Answer:

    Default parameter cannot precede a non-default parameter. -> Option D
  4. Quick Check:

    Parameter order rule violation = Error [OK]
Quick Trick: Default parameters must come after required ones [OK]
Common Mistakes:
  • Placing default parameters before required ones
  • Misunderstanding PHP parameter rules
  • Ignoring error messages

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes