Why PHP doesn’t suck anymoreby Grant Lovell on June 13, 2014
View the slideshow here: http://slides.com/grantlovell/why-php-doesnt-suck-anymore
How did we get here
Chances are if you have been in web development for any amount of time you have done some work with PHP and maybe it was a great experience like it was for me, or perhaps it was hours and hours of digging through WordPress code to figure out why a plugin wasn’t working.
You can imagine I was pretty excited about something that I thought was going to be weeks of cutting and pasting being done in a few short lines of PHP code.
A young go getter by the name of Mark Zuckerberg built a little social media site called Facebook that still uses and promotes PHP today.
Now there were a couple of other options at the time, Microsoft had ASP and Sun had JSP. I experimented with both but I didn’t want to pay for a Windows server to run ASP and it took weeks to figure out how to get a Tomcat server running to serve JSP. Comparatively PHP which was created by former U of W student Rasmus Lerdorf was free and easy to get a server running. It was also amazingly easy to get started building things and seeing the results right away. For these reasons PHP took off. And from then right up until today the biggest open source projects in e-commerce like Zen Cart and Magento, contact management like Sugar CRM, and of course Content management, with the three biggest CMSs WordPress, Joomla, and Drupal have all been built with PHP. From there came perhaps PHP’s biggest win. A young go getter by the name of Mark Zuckerberg built a little social media site called Facebook that still uses and promotes PHP today. PHP is running over 80% of known web servers and WordPress accounts for over 20% of the web.
So with the most servers, the most sites, and the biggest social media property under its belt you would think PHP would be a well respected language.
Where did we go wrong?
There is no doubt PHP has some issues, some things that don’t make sense, the order of function parameters the styling of function name and lot’s of others. For a full inventory of PHPs syntactic failings read the blog post PHP: a fractal of bad design. But as Jeff Atwood of Coding Horror concedes: “If you want to produce free-as-in-whatever code that runs on virtually every server in the world with zero friction or configuration hassles, PHP is damn near your only option.”
If you want to produce free-as-in-whatever code that runs on virtually every server in the world with zero friction or configuration hassles, PHP is damn near your only option.
Jeff Atwood, Coding Horror
There were two major factors that led to the low point of PHP. First was the prevalence of bad tutorials, it is a unfortunate feature of Google search that the most popular (and usually old) tutorials come up first. Outside of the PHP documentation the first result explaining how to connect to a MySQL database was written over 10 years ago and contains information that is just plain wrong. You couldn’t run it without getting an error, and there are far too many people who would advise to just turn error reporting off.
PHP was so successful that it became hard to change. The PHP logo is an elephant and it is suitable for many of the major open-source PHP projects. Most of these projects made it part of their mandate to support anyone using their software, this led to a situation during the transition from PHP4 to PHP5 where hosting companies wouldn’t update their servers because they were afraid of breaking old WordPress themes and plugins. And WordPress wouldn’t use improved language features because most of the servers wouldn’t support them. It was a classic catch 22 with the big open source projects that are still a concern today. In 2007 the way to move forward was the GoPHP5 initiative where over 100 projects banded together to say to make PHP 5.2 mandatory and force hosting companies into upgrading.
The rise of the frameworks
Each framework, and each major open source project was its own island with little collaboration.
Outside of the major open-source projects there was also an explosion of web application frameworks. Rails exploded on the scene, NodeJS held the promise of unifying the language on the backend and front-end. These frameworks along with .NET legitimized web applications as “real” software, and soon most new software was being developed as web application. In PHP we had Zend Framework, Symfony, and Code Igniter these frameworks were great, they led us to start thinking about design patterns in web applications and abstracting many of the flaws in the language. But the PHP community was becoming divided. Each framework, and each major open source project was its own island with little collaboration.
Composer, the FIG, and the PHP renaissance
Many of the same people involved with GoPHP5 had the insight to create the PHP-FIG (Framework Interoperability Group) to debate and decide upon common standards that frameworks and open source projects would agree to use so that code could be shared among the greater php community known as PHP Standards Recommendation or PSR. The first PSR, PSR-0 defined a way to autoload packages into a PHP project. One of the most significant outcomes of this PSR was a package management system called Composer. Composer allows php developers to mix and match the best packages of each framework. Symphony and Aura offer great routing packages, there are great OAuth packages for letting users log in to your site with Facebook or Twitter. Doctrine and Eloquent can make working with a database much more enjoyable and secure. With composer you can get packages to solve common problems very quickly.
Code that is formatted consistently is much easier to read and understand by future developers and especially when that future developer is you.
PSR-1 and PSR-2 made recommendations on how code should be styled, tabs vs spaces, camel case or sake case and more. These may seem like simple things but if you have ever worked on a team with more than couple of people these simple code styles can make or break a project. Code that is formatted consistently is much easier to read and understand by future developers and especially when that future developer is you.
Facebook has been putting on pressure by releasing HHVM which is a high performance PHP engine that they use to power their site.
Every PHP dot release has contained both beneficial new features and huge performance improvements. Facebook has been putting on pressure by releasing HHVM which is a high performance PHP engine that they use to power their site.
With PHP making up a vast percentage of the internet it is here to stay for the foreseeable future. The great thing is that around the world PHP developers are getting together both online and in person to talk about PHP. These developers are working on improving the language and each others skills. Modern PHP has been learning from what works best in other languages and adopting them as its own. Sites like PHP the Right Way, TutsPlus and Laracasts. These sites, and others like them, are making lots of high quality modern PHP tutorials with (mostly) good information. Personally, a newer Framework called Laravel has made PHP a joy to build applications in.
Our team at Vehikl has put most of our focus on working with start-ups and enterprises with startupy projects. We build these web applications in Laravel.