Do you use Object Oriented Programming in PHP?
I am teaching an advanced PHP course next semester.
I plan on covering Object Oriented PHP - but my question to you is: how much? I worked at one company where objects were not used at all - but that was a PHP 4 environment - so it was understandable. OOP is far better supported with PHP 5. I worked at another company where just about everything was OOP.
I am curious - how often is PHP being programmed procedurally or with objects? I remember reading an article somewhere from the “father” of PHP, Rasmus Lerdorf. In it, he stated that he “leans more toward procedural programming” - and that PHP was originally designed to be procedural.
Then theres the question of frameworks. Being completely honest here, I never even thought of using frameworks like MVC, Singleton, or Factory. I have just always done what works - but I have changed my thinking on this now. The idea is to make less work down the road for myself or someone else, and I am all for that.
So I am struggling with the extent I should take the frameworks and OOP. Let me know your thoughts..
Filed under: PHP



I used to be on the side of procedural and no frameworks, but that has shifted. When I built the website for Barbour Publishing, it only made sense to extract things and use objects. Otherwise, I simply found myself repetitive with my tasks. That’s the downside to procedural programming, even with a large library of functions.
When it was all said and done, I realized it would have been smarter to use a framework from the start as I ended up with a structure that abstracted the database (not full Active Record), helpers (a class that handled HTML helpers and functions), routing (done with a mix of .htaccess and programming).
Now I have moved to Ruby and Ruby on Rails, mainly due to the fact that Ruby is OO. I don’t think PHP was meant to be OO, but it has turned into that from release 5. OO in PHP is still not as extensive as a true OO language, but it is much nicer than PHP 4.
Now, anytime I am looking to build an application using PHP I will use OO PHP. To me, it makes perfect sense and I see no need to make my code look like the core of Wordpress - spaghetti strung from file to file with no sense of real organization or structure.
I don’t use OO programming for PHP at all - I think it was meant to be procedural.
I am sure others will disagree, but thats my two cents.
From what I have seen and know of PHP, which admittedly isn’t a ton, it is not great for OOP. I would say, if you’re going to do OO web development, get a real OO language and framework on top of it Ruby on Rails. Just my $0.02.
I would like to develop a Ruby on Rails course - I need to get some documentation that it is really growing and that there are jobs out there in it.