Bird
0
0

Identify the error in this code snippet:

medium📝 Debug Q7 of 15
PHP - Sessions and Cookies
Identify the error in this code snippet:
session_start();
$_SESSION = array();
echo $_SESSION['name'];
AEcho statement syntax error
BAccessing undefined session key causes notice
CCannot assign array to $_SESSION
Dsession_start() is missing
Step-by-Step Solution
Solution:
  1. Step 1: Understand $_SESSION reset

    Assigning an empty array clears all session data.

  2. Step 2: Accessing undefined key

    Trying to echo $_SESSION['name'] when it doesn't exist causes a PHP notice.

  3. Final Answer:

    Accessing undefined session key causes notice -> Option B
  4. Quick Check:

    Undefined session key access = notice [OK]
Quick Trick: Check if session key exists before echoing [OK]
Common Mistakes:
  • Ignoring undefined index notices
  • Resetting $_SESSION unintentionally
  • Assuming session keys always exist

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes