I know a guy who has been studying PHP and MySQL for 2 months. He also has some basic HTML and CSS knowledge. Yesterday he told me that a week ago he made a shopping cart on his own but without using OOP - just functions, variables and arrays. He knows how to create a class and an object, what is a method, what does __construct() do and so on, but he doesn't know when to use OOP instead of functions, variables and arrays. He asked me about this, because I have some PHP experience. I told him what I thought, but I think my answer was pretty subjective, so I ask you for help. What would you tell him? He also asked me if I can give him a few ideas what script to create in order to learn the good OOP practices. I told him some stuff like login system, product manager and I also suggested him to buy a book with C/C++ exercises since most of them are doable with PHP and this book has to contain OOP exercises (otherwise it is poor). What do you recommend?
I think he would really need to understand how OOP actually works before trying to implement it while learning. It can get a little complicated if you don't understand the underlying functionality. The product manager example would be a good one to start with, IMHO. Show him how to create an object that manages the database and logic operations for products, and I think he would get the hang of it pretty quickly.
Thanks for the answer. He is now reading the 'Classes and objects' part of the PHP's manual and trying to get the point of OOP. I think he will, because he is always searching for the logic behind the theories (he likes complicated math) Then, if he didn't find out, I will show him how to make DB queries using OOP and then he is ready to begin to make little projects using OOP.
Use a class if the code is going to be reused (say, sending emails from the site). If it's code that will only be used once, don't bother with a class. If you have simple database code I wouldn't bother writing a class to handle it. If you're doing the same thing over and over it may pay, or just a few functions may be more efficient. Two months is hardly enough time to learn what type of code might be better handled by a class - that's something that comes with experience.
Experience will give him a greater understanding - by the time he's worked on a few different systems and seen classes used well and badly. When I first learnt OOP I went a bit nuts and used them where a simple script would have done the job. OK in many ways - just overkill really.
It's actually possible to write a decent web application without the use of OOP - be it a clone of Facebook, Google, etc. You sound like you can't reuse a function. The point of OOP is to get a clear visualization of what you're coding, hence object oriented - you see codes as "objects"
I must say you should start working on core php with basic knowledge of programming. yet functions are an advantage , if you are good in programming . So if you need to take help use official site of php or w3schools where you will get a lot of help
First of all he must kno the basic concept of PHP .. Because Once you want to learn the advanced things means you must need to know about the basics very clear. http://www.cogzidel.com/services/web-development
Wow I've only read these few Post and I need a aspirin(lol) to me you Guy's sound like Charlie Browns Teacher..Don't Understand a word you all are saying..Wah Wah wah....wah wah