shane18 Posted February 20, 2010 Share Posted February 20, 2010 I can write classes, and create objects from the classes... but I don't understand the use of them... what makes a list of classes better then a list of functions.... Example... <? include("functions.php") ?> validate("Shane","Username"); That would make sure Shane follows the regex made to check usernames... That gets the job done, what makes a object better than that? Quote Link to comment https://forums.phpfreaks.com/topic/192759-php-5-oop/ Share on other sites More sharing options...
ohdang888 Posted February 21, 2010 Share Posted February 21, 2010 this is just my understanding of it, so take it for what its worth: php classes are a good way to organize data, and to a certain extent, make it more secure. you can create functions inside classes that cannot be called outside of that class, or ONLY on your __construct function, etc. Same goes with variables. Also, when you're dealing with things like User ID's, its plain easier to use a class. For example, with functions you would have to pass every var you needed through the function name (ex: username($id_of_logged_in_user, $session_data)) for EVERY function. whereas, in a class, you could just make it a public var, and use $this->id_of_logged_in_user and $this->session_data automatically without having to needlessly enter them into every function I hope that made sense Quote Link to comment https://forums.phpfreaks.com/topic/192759-php-5-oop/#findComment-1015461 Share on other sites More sharing options...
Alex Posted February 21, 2010 Share Posted February 21, 2010 OOP has nothing to do with security. If you don't know the advantages of OOP you shouldn't be using it. It's not an easy concept so don't beat yourself up if you don't understand it right away. In your limited example there would be no benefit in using OOP. If you haven't already you can check this link out to get some general information about OOP. Quote Link to comment https://forums.phpfreaks.com/topic/192759-php-5-oop/#findComment-1015463 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.