atholon Posted January 21, 2008 Share Posted January 21, 2008 I would like to know why classes are so much better than functions? The only thing I can think of is because they create a new individual function/variables without overwriting the original. Lets say I have a function: function addSomething($input) { $result = $input +1; } Why would a class be a better option? Quote Link to comment https://forums.phpfreaks.com/topic/87047-classes/ Share on other sites More sharing options...
trq Posted January 21, 2008 Share Posted January 21, 2008 This question gets asked alot and to be honest, it isn't easily explained. Classes and OOP do allow for greater fexabilty and code re-use. You won't see the point though untill you get into using them and start implimenting design patterns. Quote Link to comment https://forums.phpfreaks.com/topic/87047-classes/#findComment-445140 Share on other sites More sharing options...
atholon Posted January 21, 2008 Author Share Posted January 21, 2008 The problem is that I am not sure how I can implement them in my code. Quote Link to comment https://forums.phpfreaks.com/topic/87047-classes/#findComment-445189 Share on other sites More sharing options...
trq Posted January 21, 2008 Share Posted January 21, 2008 OOP really is a huge topic. If you are proficient in procedural code and would like to advance to using OOP style coding I would suggest getting a good book. Ive read PHP Objects Patterns and Practice several times and am still just getting my head around some of the ideas. Another good thing to do is to download / install and use one of the popular frameworks developed using design patterns as best practice. Code ignitor is a nice simple one to start with. Once you've used it a little you'll understand some of the concepts, from there you can look through there code to get an idea of how it all works. With that in mind, you may then like to impliment some of the ideas in your own code. Quote Link to comment https://forums.phpfreaks.com/topic/87047-classes/#findComment-445226 Share on other sites More sharing options...
Daniel0 Posted January 21, 2008 Share Posted January 21, 2008 If you want to learn OOP then I'd suggest Zend Framework to CodeIgnitor as you'll handle more things yourself thus dealing more directly with the classes yourself. Still, ZF probably has a higher learning curve than CI does, so for a beginner CI may be easier to comprehend. Something to read is the OOP section of the manual as well as some of the things in this topic. Quote Link to comment https://forums.phpfreaks.com/topic/87047-classes/#findComment-445238 Share on other sites More sharing options...
taith Posted January 22, 2008 Share Posted January 22, 2008 I would like to know why classes are so much better than functions? a) their not... both have their unique uses and strengths/weaknesses (i prefer procedurial for php, so... i'll fight that case) if you design procedural functions properly... they can work to a simlar scope as OOP... using the return; method, you can make it so you can have one function, giving different data to an unlimited amount of variables... which can then be used however you see fit... same as OOP only its FAR easier to jump between non-related functions... however... if you were to use a client sided programming language(javascript for example) OOP wins hands down... you can edit code live, and access many different otherwize dormant areas, that procedurial would take FOREVER to get to... you can also use timers, which would be VERY inaccurate with procedurial! i'm not saying procedurial is better then OOP or vice versa... just both have their differences... and both are equally as useable... (in my opinion... OOP has no place in server sided languages... but! many people like it... so... its 100% down to the user ) Quote Link to comment https://forums.phpfreaks.com/topic/87047-classes/#findComment-445768 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.