The next era of PHP

Submitted by Larry on 30 May 2015 - 5:57pm

2015 is turning into a watershed year for PHP. Many projects either have or will release new major versions, including Zend Framework, Symfony, Laravel, Guzzle, Drupal, Slim, and many others. And of course there's PHP 7 itself, coming this fall.

I'll talk more on those later, but for the moment I want to focus on one other major new development this year: PSR-7.

PSR-7's Editor Matthew O'Phinney has already written at length about PSR-7, the new HTTP messaging spec from the Framework Interoperability Group. If you want to get a grounding on what PSR-7 is and how it came to be, see his blog post.

First off, I want to personally and publicly thank Matthew for his work as Editor. FIG discussions can be touchy at times, especially with a spec as fundamental and important as HTTP handling, but he handled himself and the discussion with a calm that I see in few people period, to say nothing of those in leadership positions. I honestly don't think PSR-7 would have ever happened without not just his work but his calm and level-headed diplomacy. MWOP, you're our hero! And happy birthday to both you and PSR-7. :-)

More relevant to the future, though, is how quickly PSR-7 is being adopted. It's been only two weeks since it officially passed, yet it's already making inroads in many major projects. Unsurprisingly, Zend Framework 3 (which Matthew leads) is going to use PSR-7. The Slim Framework will adopt PSR-7 in version 3. Guzzle 6 is already out, featuring PSR-7 support on the client side.

And then today came the news that Symfony has released a bridge library, targeted at the new Symfony 2.7, that translates cleanly between its HttpFoundation (which pre-PSR-7 was the de facto standard HTTP request/response library used by dozens of projects) and PSR-7, with integration to support PSR-7 requests directly in controllers. Even more impressive, to create PSR-7-compatible messages it's using Diactoros. That confusingly-named library was originally phly/http, Matthew's proof-of-concept/reference implementation while building PSR-7. It has since been merged into Zend Framework (or at least its namespace). Which means that, yes, using PSR-7 in Symfony or Symfony-based projects requires a Zend Framework library.

Which is totally frickin' awesome! No ego, just collaboration. As PHP should be. As a community should be. As the future of PHP will be.

When working on PSR-7, several of us noted that it would be made or broken by whether or not Zend Framework and Symfony adopted it; they're the 800 lb gorillas in the PHP space, and Symfony in particular was one of the very early drivers of the PHP Renaissance of the past few years with its emphasis on loosely coupled reusable high-quality components. We knew if ZF and Symfony rejected it, all our work would be for nought. If they were on board, PSR-7 was a done-deal.

Well, they're both on board. PSR-7 is a done deal, and the future of PHP HTTP handling. What's more, it's a sign that the PHP community as a whole is maturing and embracing cross-project collaboration and cooperation. May that collaboration continue and grow even stronger.

Although it was contentious, I believe that, long term, the decision to make PSR-7 messages immutable will also prove to be critical to PHP's future. Although immutable, they are still highly usable thanks to the availability of "return modifier" methods. I suspect that immutability will influence the direction of later work, both within FIG and elsewhere. That's a good thing, because immutable objects help to enforce decoupling and enable a wider range of usage patterns, such as persistent PHP daemons (such as React PHP). Keep an eye on that concept over the next few years.

For now, if you haven't had any PSR-7 cake yet, go treat yourself. Job well done, everyone! 2015 begins the next era of PHP's evolution, and I for one welcome our new cooperation-based overlords!