OO or procedural PHP for website?

I would like to recommend WordPress, over writing code from scratch for fairly simple site.

All you need to webspace and little time to learn how to customize wp.

Check out the showcase

If you still want to write from scratch.. its better to follow OO, may be you can use frameworks like Zend or Kohana

Cheers


but it is important that the code is fairly easy to understand for a programmer with a decent amount of PHP experience.

Readability of code is not tied to a programming paradigm but to how the code is written. I have seen my fair share of spaghetti OOP (including my own) and I have seen an equal amount of procedural messes. If the code is well written, even someone without a decent amount of PHP knowledge should be able to follow along.

I'm guessing most PHP-programmers are not used to OO-code, so perhaps this is one point in favor of procedural code?

I doubt this. I've been to a number of conferences and no one there seemed to have any problems with OOP. In fact, I didnt even see a single line of procedural code. Also, all of the major frameworks are full OOP. You will find the procedural paradigm mainly in PHP4 applications and when looking at rookie code.

But to answer your question: I'd say use OO if that is what you and your developers are comfortable with. Personally, I find procedural code in the View part a bad idea, because you will likely end up intermingling logic and presentation code for completely unmaintainable templates. See the POEAA's Web Presentation Patterns for some more maintainable approaches.

You don't have to use MVC if you feel its too oversized. Use a Page Controller if you like. But then again, MVC aint that hard to implement either and there is plenty frameworks out there that will take the brunt of work away from you.


The first thing to accept when writing PHP is that it is primarily a templating language. PHP is meant to be put in an HTML document to make bits of the document dynamic.

PHP is capable implementing OO designs, but the code you write will not be nearly as nice as similar C# code (and possibly Java, but I don't know Java to comment).

You say you'll have an interface for creating articles - that does sound more complex than simply adding a little dynamic content here or there. This might benefit from the OO treatment.

On the other hand, there are many PHP CMSs that are already made, such as wordpress, Drupal and Joomla!, that might suit your needs out of the box.

In conclusion - if a pre-made solution doesn't suit you, go the OO route with some procedural script to tie it all together.


It all depends on your aim.

  • If you do not wish to extend your project later on a procedural approach is ok.
  • If you are able to develop part of your code faster using predefined objects then that is the way to go.

  • If can you just write down your code from top to bottom without much effort "procedural" is fine too.

Tags:

Php

Oop