Bird
0
0

Find the bug in this PHP code:

medium📝 Debug Q7 of 15
PHP - Type Handling
Find the bug in this PHP code:
$var = '';
if (is_null($var)) {
echo 'Null';
} else {
echo 'Not Null';
}
AMissing semicolon after echo
BEmpty string is not null, so condition is wrong
Cis_null() cannot be used on strings
DVariable $var is not defined
Step-by-Step Solution
Solution:
  1. Step 1: Understand is_null() behavior

    is_null() returns true only if variable is exactly null, empty string is not null.
  2. Step 2: Analyze condition result

    Since $var is '', condition is false, so 'Not Null' is printed.
  3. Final Answer:

    Empty string is not null, so condition is wrong -> Option B
  4. Quick Check:

    is_null('') = false [OK]
Quick Trick: Empty string is not null [OK]
Common Mistakes:
  • Confusing empty string with null
  • Thinking is_null() errors on strings
  • Ignoring variable initialization

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes