# [web] php and $this This topic is 4716 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic. If you intended to correct an error in the post then please contact us. ## Recommended Posts I've been developing a login system for a website, with a class that represents a logged in user. One type of account, administrator, should have more functionality than other users. The way I originally did this was to have the functions specific to administrators built into the user class, but each time one of these functions was called, it checked to make sure that the user was an administrator. I've finally decided that this is not good design, and I'm trying to come up with a better way to do it. One method I've come up with is to have an administrator class that extends the user class, but the problem with this is that I don't know which type of class to create until after the user has logged in. I'd like the class to take care of itself, so the page using it shouldn't have to check and see if it's an administrator, then reassign the class type. Can I use$this to assign itself to a different type of class? This really doesn't seem like good design either, even if it would work, so any other ideas for how to best design this would be greatly appreciated. I'm building this under a three-tier architecture, so I could have the middle tier check and reassign the class, but this still doesn't seem like a good idea. Thanks again, I really appreciate your help. Edit: After thinking about this for a while, the idea that $this could reassign itself doesn't make any sense, and I don't know how any language could pull it off. How about, if a user is an administrator, a new object is created as a variable in the user class that holds administrator functionality? This still doesn't seem ideal; extending the user class to create a more functional administrator class just seems like the most logical solution. I'm still not sure about the best way to do this, though. If anyone experienced in design could give me their thoughts, I'd appreciate it a lot. [Edited by - sofsenint on July 18, 2005 8:42:49 PM] #### Share this post ##### Link to post ##### Share on other sites Advertisement What kind of functionality does the administrator class have that the user class doesnt? Is it possible for you to have the page check to see if the user is an administrator before allowing the user to perform a certain action? In my authentication system I have one user class, User, which has a method GetType() which returns the type of the user, Guest, Normal, Admin. If there is a function that requires certain access then that function first checks to see if the user has that access. For example$user = GetCurrentUser();

// Delete something from the database
if ($user->IsLoggedIn() &&$user->GetType() == 'Admin')

• 37
• 12
• 10
• 10
• 9
• ### Forum Statistics

• Total Topics
631360
• Total Posts
2999552
×