Jump to content

Recommended Posts

I have a class User which when created as an object gets the information for a specific user and has functions that the user could use (change email, add credits etc.). I now would like to add some functions for adding, deleting and managing users, and I'm not sure if I should create a new class or put it in the old one.

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/105942-class-problem/
Share on other sites

I have a class User which when created as an object gets the information for a specific user and has functions that the user could use (change email, add credits etc.). I now would like to add some functions for adding, deleting and managing users, and I'm not sure if I should create a new class or put it in the old one.

 

Thanks

 

There are really two questions you have to ask:

 

1. Should all users be allowed to have those administration capabilities (which I put in bold) available to them from the outset?

2. Does it make sense to put functions that make sweeping system changes into the same class that previously allowed only individual changes?

 

I can't think of a reason, other than wanting to save a few keystrokes, to shoehorn administration functions into a generic user class.  This sort of thing is better left to an administration class of some sort that is responsible for largescale user manipulation.

Link to comment
https://forums.phpfreaks.com/topic/105942-class-problem/#findComment-542970
Share on other sites

I did it this way:  Make an Admin class that does admin functions.  If $user->is_admin (or however you check), instantiate the $admin class.  It is only instantiated on admin panel screens for 'better' security.

 

If there's a better way, let me know.  I'm still wrapping my head around OOP.

Link to comment
https://forums.phpfreaks.com/topic/105942-class-problem/#findComment-543102
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.