I'm currently learning OOP in php and enjoying it, but I do have one question. Is there a general guideline that one can follow to determine if a particular problem should be solved in OOP vs procedural programming?
So far I find one of PHP's strengths is it's ability to switch from OOP to procedural if the situation requires it. However how do you know when to make the switch to OOP?
Any reasonably complex project can benefit from OOP. It can be much easier to maintain. If you are having trouble with file uploads for instance, and you are using a file upload class, you can take that class outside of the project on a test page, and pound on it a little, till you find the problem.
Otherwise you are forced to wade through a lot of other code and perhaps filling out large numbers of required values in a form, just so you can test that one simple feature. Sometimes the bug is wider spread but if you are using mostly OOP, the problem is likely isolated.
The other instance where OOP really shines is in cases where you find yourself writing the same code over and over with slight differences. That can get tired really quick.
If you build that functionality into a class, you may never need to write that code again. Write an HTML table class and never have to write tabular data code for your database again. Just feed it the recordset and let it go.
For that reason small projects can benefit too. You don't need a full blown MVC framework to do a simple contact form, but that is no reason to go back to procedural programming, if you can put together a nice validation/mail/spam protection class bundle, and deploy it in half the time, and move on.
You can end up with a very nice re-usable and easily patched/upgradable toolbox for just about anything.
There will be certain code that you will never get an error from again, because once the class has been debugged, you don't have to worry about that occasional mistake of forgeting a semicolon or curly brace because you are re-writing the code for the hundredth time, on auto pilot.
I've heard some people say turn anything into a class that can be feasibly turned into a class, but to me that seems heavy handed. Although I've only had a bit of experience with OOP I've found it really helpful when doing similar tasks again and again i.e. database access etc.
OOP is a style of programming. You can use it all the time, and if that makes you feel comfortable, I think you should. Personally, I typically turn my procedural code into OOP, when it reaches more than about a screen in height.