Jump to content

Quicky about using unset() in 'return' value


timmy0320

Recommended Posts

I am using session_set_save_handler() to store my sessions in the database and also added a couple more functions for my script so I don't have to use the $_SESSION variable, etc. Yeah, this is a personal choice because I hate using gaudy looking $_SESSION as variables, etc. My code is below for my script functions:

 

<?php
    // create a session.... for the script
    function _create($name, $data) {


        $name = _sql_escape($name);
        $data = _sql_escape($data);

        return $_SESSION[''.$name.''] = $data;
    }

    // read the session... for the script
    function _read($name) {
        $name = _sql_escape($name);
        return $_SESSION[''.$name.''];
    }

    // unset the session... for the script
    function _unset($name) {
        $unset = unset($_SESSION[''.$name.'']);
        return $unset;
    }
?>

 

The read and write work, but the unset() won't work just returning it or placing it in a variable I get this error message:

 

Parse error: syntax error, unexpected T_UNSET

 

When I used:

unset(_read('registered'));

I got:

Fatal error: Can't use method return value in write context 

 

 

Any ideas? I really don't want to use $_SESSION on my pages because to me it just looks like crap. Maybe I have OCD or something lol

Link to comment
https://forums.phpfreaks.com/topic/97589-quicky-about-using-unset-in-return-value/
Share on other sites

you can't unset the function

try this

<php
    function _remove($name) {
        $name = _sql_escape($name);
        unset($_SESSION[''.$name.'']);
    }
?>

 

or try this

<php
unset(_getVar($name));

    function _getVar($name) {
        $name = _sql_escape($name);
        return $$_SESSION[''.$name.''];
    }
?>

 

**untested

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.