note 69559 added to function.session-destroy

From: Date: Sun, 10 Sep 2006 20:04:52 +0000
Subject: note 69559 added to function.session-destroy
Groups: php.notes 
Request: Send a blank email to php-notes+get-116988@lists.php.net to get a copy of this message
The native value of an uninitialized $_SESSION is NULL. <?php $before=@gettype($_SESSION); session_start(); $after=@gettype($_SESSION); print $before.' '.$after.'<br>'; //prints: NULL array ?> It seems therefore more appropriate to unset it via $_SESSION=null; In fact in case your script are checking whether a session exists by isset($_SESSION) which is a legitimate and reasonable check, if you try to unset the session via $_SESSION=array() the check would return true. This would not happen if you unset by $_SESSION=null; <?php session_start(); if(isset($_SESSION)){ print 'A session exists after having used session_start()<br>'; } $_SESSION=array(); if(isset($_SESSION)){ print 'A session exists after having reset it to $_SESSION=array()<br>'; } session_destroy(); if(isset($_SESSION)){ print 'A session exists after having called in session_destroy() AND having set $_SESSION=array()<br>'; } $_SESSION=null; if(isset($_SESSION)){ print 'A session exists<br>'; } else{ print 'A session does NOT exist anymore after having set it to $_SESSION=null'; } ?> That prints: A session exists after having used session_start() A session exists after having reset it to $_SESSION=array() A session exists after having called in session_destroy() AND having set $_SESSION=array() a session does NOT exist anymore after having set it to $_SESSION=null Am I mistaken? ---- Server IP: 213.92.11.19 Probable Submitter: 84.221.223.64 ---- Manual Page -- http://www.php.net/manual/en/function.session-destroy.php Edit -- https://master.php.net/note/edit/69559 Del: integrated -- https://master.php.net/note/delete/69559/integrated Del: useless -- https://master.php.net/note/delete/69559/useless Del: bad code -- https://master.php.net/note/delete/69559/bad+code Del: spam -- https://master.php.net/note/delete/69559/spam Del: non-english -- https://master.php.net/note/delete/69559/non-english Del: in docs -- https://master.php.net/note/delete/69559/in+docs Del: other reasons-- https://master.php.net/note/delete/69559 Reject -- https://master.php.net/note/reject/69559 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#116988) next »