timmy0320 Posted March 24, 2008 Share Posted March 24, 2008 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 More sharing options...
MadTechie Posted March 24, 2008 Share Posted March 24, 2008 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 Link to comment https://forums.phpfreaks.com/topic/97589-quicky-about-using-unset-in-return-value/#findComment-499306 Share on other sites More sharing options...
ansarka Posted March 24, 2008 Share Posted March 24, 2008 change your function to function _unset($name) { unset($_SESSION[''.$name.'']); return 1; } // you cant assign an unset function result to a variable Link to comment https://forums.phpfreaks.com/topic/97589-quicky-about-using-unset-in-return-value/#findComment-499310 Share on other sites More sharing options...
timmy0320 Posted March 24, 2008 Author Share Posted March 24, 2008 Ah, I'm retarded. Thanks Link to comment https://forums.phpfreaks.com/topic/97589-quicky-about-using-unset-in-return-value/#findComment-499324 Share on other sites More sharing options...
wildteen88 Posted March 24, 2008 Share Posted March 24, 2008 Also there is no point in doing ''.$var_name.'' when using variables, just use $varname, eg: unset($_SESSION[$name]); Link to comment https://forums.phpfreaks.com/topic/97589-quicky-about-using-unset-in-return-value/#findComment-499367 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.