ttocskcaj Posted January 12, 2011 Share Posted January 12, 2011 What do you think of my user class so far? Room to improve, things to change etc. I'm still getting the hang of this oop thing. http://pastebin.com/fPFk21k4 Quote Link to comment https://forums.phpfreaks.com/topic/224156-my-user-class/ Share on other sites More sharing options...
necken18 Posted January 12, 2011 Share Posted January 12, 2011 Don't mix the var and the public keyword. they have the same functionality. Quote Link to comment https://forums.phpfreaks.com/topic/224156-my-user-class/#findComment-1158257 Share on other sites More sharing options...
lastkarrde Posted January 12, 2011 Share Posted January 12, 2011 Move the instantiation of the settings class into the constructor and make it available for all methods to use. eg (in the class) public $settings; function __construct() { $this->settings = new settings(); } Then in your methods (isBanned, login, register) you can refer to the settings object as $this->settings, rather than repeating code to instantiate. This leaves your code cleaner, less lines and more maintainable. Quote Link to comment https://forums.phpfreaks.com/topic/224156-my-user-class/#findComment-1158288 Share on other sites More sharing options...
ttocskcaj Posted January 13, 2011 Author Share Posted January 13, 2011 Cool thanks for the advise necken18 I'm not sure what you mean? What line have I mixed them? Quote Link to comment https://forums.phpfreaks.com/topic/224156-my-user-class/#findComment-1158806 Share on other sites More sharing options...
lastkarrde Posted January 13, 2011 Share Posted January 13, 2011 You declared your class variables with var and some of your methods with public. I advise putting them all as public (or private/protected). var is PHP4-ish. Quote Link to comment https://forums.phpfreaks.com/topic/224156-my-user-class/#findComment-1158809 Share on other sites More sharing options...
ttocskcaj Posted January 13, 2011 Author Share Posted January 13, 2011 Ah ok, It's just something from a tutorial, probably old lol. Quote Link to comment https://forums.phpfreaks.com/topic/224156-my-user-class/#findComment-1158818 Share on other sites More sharing options...
KevinM1 Posted January 13, 2011 Share Posted January 13, 2011 Don't use die for error handling. Throw exceptions and catch them gracefully. Quote Link to comment https://forums.phpfreaks.com/topic/224156-my-user-class/#findComment-1158882 Share on other sites More sharing options...
ttocskcaj Posted January 14, 2011 Author Share Posted January 14, 2011 Yea, It's not finished yet lol, I haven't done any error catching or string cleaning etc. I just have the die's there so I know my query's fail, which they quite often do Quote Link to comment https://forums.phpfreaks.com/topic/224156-my-user-class/#findComment-1159193 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.