views:

69

answers:

2

I am very curious as to why all the main PHP frameworks like zend use setter and getter methods to set and get basic $_SESSION['user'] variables? I am doing it myself right now but I really don't know why I am, other then the fact that I see it being done fairly often by others now. So in theory at least, it seems like wrapping these into a class would just add more overhead and I just want to know if there is any reasoning behind this trend?

+5  A: 

One reason is that most of them allow you to store the session in a different way like a database. So you can always use get/set no matter how your session is handled.

EDIT: CodeIgniter for example checks if the session is valid after it got called (IP, Browser). So you don't have to call a "check function" right after you called session_start().

Tim
That is the exact reason that I though until I realized that this can be done without wrapping it in a class, you can set the default session handler to use database without using a class or function
jasondavis
Yes, you can set your default session handler to be database driven, but the classes that implement sessions often have additional functionality built in like caching or a different method for storing session data in the database.
Wally Lawless
+1  A: 

Its so that you can lazy load the session - normally you would have to run session_start() before accessing any session variables, by using getters and setters, you can have this action performed on demand.

Will Earp