Bird
0
0

What will be the output of the following PHP code?

medium📝 Predict Output Q13 of 15
PHP - Sessions and Cookies
What will be the output of the following PHP code?
session_start();
$_SESSION['user'] = 'Alice';
session_unset();
echo isset($_SESSION['user']) ? 'Exists' : 'Not exists';
AExists
BError: Undefined index
CNot exists
DEmpty string
Step-by-Step Solution
Solution:
  1. Step 1: Set and then unset session variables

    The code sets $_SESSION['user'] to 'Alice', then calls session_unset() which clears all session variables.
  2. Step 2: Check if session variable exists after unset

    Since variables are cleared, isset($_SESSION['user']) returns false, so output is 'Not exists'.
  3. Final Answer:

    Not exists -> Option C
  4. Quick Check:

    session_unset() clears variables = C [OK]
Quick Trick: session_unset() clears variables, so isset returns false [OK]
Common Mistakes:
  • Assuming session_unset() deletes session completely
  • Expecting variable to still exist after session_unset()
  • Confusing session_unset() with session_destroy()

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes