Bird
0
0

Identify the error in this PHP function:

medium📝 Debug Q14 of 15
PHP - Functions
Identify the error in this PHP function:
function multiply($x, $y) {
  $product = $x * $y;
  return
  $product;
}
AMissing semicolon after return
BReturn statement split incorrectly, returns nothing
CVariable $product is undefined
DFunction missing closing brace
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the return statement split

    The return is on one line alone, so PHP treats it as returning nothing immediately.
  2. Step 2: Understand effect of line break after return

    The next line $product; is unreachable and not part of return, causing function to return null.
  3. Final Answer:

    Return statement split incorrectly, returns nothing -> Option B
  4. Quick Check:

    Return must be on same line as value [OK]
Quick Trick: Keep return and value on same line to avoid empty return [OK]
Common Mistakes:
  • Splitting return and value on separate lines
  • Assuming return reads next line automatically
  • Ignoring PHP's automatic semicolon insertion

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes