开发者

Why do most PHP frameworks use set/get for Session variables?

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 开发者_如何学Goany reasoning behind this trend?


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().


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜