Bird
0
0

Identify the error in this PHP code snippet:

medium📝 Debug Q14 of 15
PHP - Variables and Data Types
Identify the error in this PHP code snippet:
$var = null
if ($var === null) {
echo 'Null value';
}
AIncorrect comparison operator
BMissing semicolon after assignment
CNull cannot be assigned to variables
DEcho statement syntax error
Step-by-Step Solution
Solution:
  1. Step 1: Check syntax of assignment line

    The line $var = null is missing a semicolon at the end, which is required in PHP.
  2. Step 2: Verify other parts of the code

    The comparison and echo statements are correct and valid.
  3. Final Answer:

    Missing semicolon after assignment -> Option B
  4. Quick Check:

    Every statement needs ; in PHP [OK]
Quick Trick: Check for missing semicolons after statements [OK]
Common Mistakes:
  • Forgetting semicolon after assignment
  • Thinking null can't be assigned
  • Misreading === as wrong operator

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes