Do I need to grab a PHP class object in every method in a class? -
i working on php classes, have session class used set , values session variables, need have access session class object in every other class made singleton method in session class , in other class's methods can call session object this....
$session = session::getinstance();
this return session object me use or else start new session object if 1 has not been started yet.
so question, if have user class , database class , each class had 10 methods in each needs access session object, need run code above inside each , every method or 1 time inside class , methods have it? new not sure??? thanks
in singleton pattern, indeed have that.
an alternative might add session object protected member $session
of class in constructor, , accessing each method $this->session
.
if want read broader discussion how arrange , use helper , library objects in php, asked related question once yielded interesting answers.
Comments
Post a Comment