can session values be null if they are not set? or should I use isset all the time?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There are many ways of doing this, all OK. For example:
empty($_SESSION['a'])will return true if the value doesn’t exist or is empty (empty array, zero, empty string, etc)isset($_SESSION['a'])will return true if the value existsarray_key_exists('a', $_SESSION)will also return true if the value existsYou shouldn’t just use
$_SESSION['a'] == null, because ifadoes not exist in the$_SESSIONarray, you will receive a notice.