How to avoid deprecation warning by replacing session_unregister with $SESSION[] after upgrading to PHP 5.3?

12,220

Solution 1

Quoting the doc (take a look at that page, it says quite some interesting stuff ;-) ) :

session_unregister() unregisters the global variable named name from the current session.

To remove an entry from an array, you can use unset. So, instead of

session_unregister('my_var');

You can use

unset($_SESSION['my_var']);

Which, in your case, I guess, means :

unset($_SESSION[$serverWideUniqueIdCode]);


Still, you probably don't want to call unset on the whole $_SESSION variable. Quoting the doc a second time :

Note: If $_SESSION (or $HTTP_SESSION_VARS for PHP 4.0.6 or less) is used, use unset() to unregister a session variable. Do not unset() $_SESSION itself as this will disable the special function of the $_SESSION superglobal.

Solution 2

$_SESSION = array();

Share:
12,220
Angry Dan
Author by

Angry Dan

web/software developer, .NET, C#, WPF, PHP, software trainer, English teacher, have philosophy degree, love languages, run marathons my tweets: http://www.twitter.com/edward_tanguay my runs: http://www.tanguay.info/run my code: http://www.tanguay.info/web my publications: PHP 5.3 training video (8 hours, video2brain) my projects: http://www.tanguay.info

Updated on June 28, 2022

Comments

  • Angry Dan
    Angry Dan almost 2 years

    I just installed PHP 5.3 and am weeding out consequent "deprecated" warnings.

    It says session_unregister() is deprecated in:

    session_unregister($serverWideUniqueIdCode);
    

    and the replacement seems to be $_SESSION[].

    So what would be the syntax with $_SESSION[] to express the same thing?