0

I was just wondering if the way in which I am passing variables to different objects is the best way of doing things. So I have a User class which handles all of the information to do with the session. Within that user class is a variable (private) called isloggedon which is a bool set at false by default. Ideally I need to pass that variable onto the usermanage class so I can allow a logged on user to do things such as make new posts. Here is how I'm doing it at the moment...

$user = new User();
$userManage = new UserManage($user->checkLoggedOn());

So as you can see I have an instance of user. Within the user class I have a method which returns the isloggedon variable (checkLoggedOn()) so that within the user manage it knows whether the user is logged on or not.

Please put my mind at ease and tell me whether it is the best approach.

Thanks a lot

9
  • For a user manager class I would inject in the user and let the manager ask the user it it is logged in Commented Jul 25, 2013 at 16:57
  • @Orangepill Where would the User class come in then though if everything is handled in the UserManager class? Commented Jul 25, 2013 at 16:59
  • 1
    The user class would still contain "isLoggedOn" and other "user" related variables. The manager would just perform checks and operations that need a "user" in order to be done. Commented Jul 25, 2013 at 17:03
  • Constructing with the results of the isLoggedOn call gives the UserManager any indication of who is logged in ... wouldn't be able to manage much with just that. Commented Jul 25, 2013 at 17:05
  • @Orangepill Ahh I see so I guess then the usermanager class would only have to check for a null username/userid(possibly) value to determine whether they are eligible to edit posts. Thanks a lot guys :) Commented Jul 25, 2013 at 17:09

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.