The PHP paradigms poll results: OOP wins
After two weeks of gathering votes, the PHP paradigms poll is now closed. With 216 votes (73%), the winner paradigm in popularity is Object-Oriented Programming. The old procedural approach to PHP, which has given fame to Wordpress and Drupal, is coming to an end. Even Drupal 7 has an object-oriented database layer as a primary component, and this paradigm is by far the most diffused in the world for web sites and applications written in high level languages (different from C).
Only 6% of votes went to procedural and the 8% to spaghetti-like programming (which we can take as a joke, I hope).
The functional paradigm makes up for the remaining 13%, a growing minorance in the PHP world.
PHP is not LISP and this is not a mistery either. However I feel that the functional constructs would become a well-treated minority in the codebases, able to fill the gaps where using an object or a Command pattern would be needlessly verbose.
We already know several situations where anonymous functions and closures come handy: the returnCallback() matcher in PHPUnit, or the small methods for formatting domain data (in the realm of View Helpers). There is also a PHP 5.3 adoption curve that has to be considered before they can be included safely in our projects. We all hope this curve won't be steep.
Frameworks vs. CMS
OOP emerges as a winner since while in the previous years the buzz in the PHP world was always on CMS and Wordpress, due to their long list of features, now it is on frameworks, due to their flexibility. Frameworks are naturally oriented to objects, to scale at a level of complexity never imagined before.
In a single page of a framework-built web page, you can leverage components like layouts, database queries and updates, access to web services, cache and formatting of currencies, internationalization and more. All dealt with and kept in its place, while adding a new page becomes a matter of ten or twenty lines of code.
The only problem with object-oriented programming in PHP is the lack of support from the language, which is evolving fast as I commented, but not in all the directons and certainly not on the most correct track.
>[...] the OO paradigm of PHP 5 borrows heavily from Java, and with its object handlers system gives the possibility of building large object graphs like the ones of frameworks such as Zend or symfony. There is still much work to be done however - SPL really sucks from a design point of view (its component are used for performance), and things like collections or lists still have to be created in userland code.
Fortunately, frameworks implements in userland code what is missing. PHP as a language is fairly complete (compare it to C); the problem is in the lack of object-oriented libraries directly available with the interpreter. Java has its Collections Framework; PHP has arrays. PHP has many features for accessing web services or managing internationalization, but they are not object-oriented: we make up with frameworks all the time.
There is a tie-in towards the framework, or ORM however: the upcoming Doctrine\Common\Collections\Collection is an example. Try do lazy loading with an array: you can't. So application code growing dependent on the library is something we must accept for now.
On the whole, object-oriented programming and libraries are able to make PHP scale in complexity instead of in user size, in directions like the enterprise and workflow systems. It's no mistery why it won this poll.
You find this result consistent with what you're seeing in the PHP community?
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)