Bird
0
0

Identify the error in the following PHP code using the null coalescing operator:

medium📝 Debug Q14 of 15
PHP - Operators
Identify the error in the following PHP code using the null coalescing operator:
$value = ?? 10;
AMissing left operand before ?? operator.
BMissing semicolon at the end.
CUsing wrong operator, should be ?: instead of ??.
DNo error, code is correct.
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the operator usage

    The null coalescing operator requires a left and right operand, like $a ?? $b.
  2. Step 2: Identify the error in the code

    The code has ?? 10 without a left operand before ??, which is invalid syntax.
  3. Final Answer:

    Missing left operand before ?? operator. -> Option A
  4. Quick Check:

    Null coalescing needs both operands [OK]
Quick Trick: Both sides needed for ?? operator [OK]
Common Mistakes:
  • Leaving out left operand
  • Confusing ?? with ternary operator
  • Ignoring syntax errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes