Bird
0
0

Identify the error in this PHP code:

medium📝 Debug Q6 of 15
PHP - Conditional Statements
Identify the error in this PHP code:
if ($var ??) {
echo 'Set';
}
ASyntax error due to incomplete null coalescing operator
BNo error, code runs fine
CRuntime error because $var is undefined
DLogical error, condition always false
Step-by-Step Solution
Solution:
  1. Step 1: Check null coalescing syntax

    The operator ?? requires a right operand; here it is missing.
  2. Step 2: Identify error type

    Missing right operand causes a syntax error.
  3. Final Answer:

    Syntax error due to incomplete null coalescing operator -> Option A
  4. Quick Check:

    Null coalescing needs both operands [OK]
Quick Trick: Null coalescing must have both sides [OK]
Common Mistakes:
  • Leaving right side empty
  • Assuming ?? works alone
  • Ignoring syntax errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes