TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Absolute Beginners (http://www.talkphp.com/absolute-beginners/)
-   -   Session class.... (http://www.talkphp.com/absolute-beginners/4225-session-class.html)

allworknoplay 05-04-2009 06:54 PM

Session class....
 
I did a search and didn't find much about this so I'd like to ask...


As I try to implement more OO code into my everyday life. I am struggling to find the benefits of creating a session class...

Here is how I normally use sessions...(small snippit of course)

My main header file starts the session so it is available on all pages that include the header file...

session_start();


As the user successfully logs in, I create a session for them that would include your basic needs, info taken from the DB...

(SQL query and results)

$_SESSION['username'] = $rows["username"];
$_SESSION['userid'] = $rows["userid"]

etc etc....



So that's about it. As I need to access the username, I just simply access the superglobal array throughout the site...

ex:
echo "Username: " . $_SESSION['username'];




I read a good OLD post just now from Xenon about not trying to make everything you do in OO....and I do think that makes sense too...

So is making a session class overkill? Are there any benefits to it especially since it's a superglobal array that I can access anywhere on the site by just calling: $_SESSION[]...

Am I not seeing the bigger picture because I'm using it in such a basic way?

Thanks!

allworknoplay 05-04-2009 09:57 PM

Ok so here's an example....say I want to access a session variable the "procedural way"..

echo "$_SESSION['username']";



The OOP way:


function getVar($varName)
{
return $_SESSION[$varName];
}

echo $session->getVar(username);


It almost seems like going out of your way to use OO for session data?


All times are GMT. The time now is 10:51 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0