PHP: Ecosystem Update

Posted: 2012-07-10
Category: PHP

Don't worry guys, this isn't another PHP apologist or PHP hater blog. We've all had enough of those recently. This is a quick heads up on two projects that are doing what they can to make the PHP ecosystem a better place.

Framework Interoperability Group (PHP-FIG)

I think most of you by now will have heard of the PHP-FIG or PSR-1 and PSR-2 in some form or another. There have been loads of arguments about this for and against, with the good old fashioned snake_case v camelCase and tabs v spaces arguments coming back for a new round. Nobody agrees - go figure.

These silly arguments about brackets and spaces really clouded the point of what the FIG is trying to do and as member I felt I should help out however I could along with the other members to fix the FUD going around. Paul M Jones wrote an awesome FAQ style blog post that answered a lot of these questions when PSR-1 and PSR-2 were accepted but to many people this was just "some guys blog", we really needed some central location for all this information.

So, on a mission to help people know what the hell the FIG are up to, I grabbed a domain, pestered a few people to set something up on GitHub pretty soon they had a website set up on GitHub Pages: http://php-fig.org/. A few of the guys chipped in with the content, and now there is a shiny new PHP-FIG FAQ page!

If you still have any questions, doubts or concerns about the FIG then please just comment here, raise issues on GitHub, make suggestions in the form of pull requests, whatever. The point of this page is that it answers questions and stops everyone running around going "THE MEAN MAN ON THE INTERNET IS TELLING ME I CANT PUT BRACKETS ON A NEW LINE!!1!1".

Seriously, nobody cares, that is not the point.

The point is that the frameworks and component developers have come together to build usable recommendations for interoperable code, so I can build my projects using a little bit of Symfony (love their YAML parser) and a little bit of FuelPHP (grabbing me some Validation) and throw it all into some other framework, and everything is the same.

Beyond the basic interop factor, the way I see it, by reducing the number of active style guides around we'll have less of these religious battles in the future. Right now you love coding in a certain way, probably because the framework or CMS you develop with always did things in a certain way. If all of these frameworks used the same style new developers are more likely to code in the same way, meaning there will be less of those office arguments about where brackets are going and everything else.

Ruby, Python, etc are all pretty much on the same page with coding style, if PHP can get there too that that is one nice tick in the box for PHP (even if it doesn't change the world).

PHP The Right Way

As a PHP developer I often have friends ask "What is the best way to get started with PHP?". My usual answer is "I don't know, that was 12 years ago, look at tutorials or something.". I can barely remember what sites I looked at, or what blogs gave me bits of advice. I have no idea where to send them and its been like that for years.

About 3 days ago Josh Lockhart (author of the micro-framework Slim) made an initial commit on a new website, which was another GitHub Pages public repository, with the URL phptherightway.com. He sets out to solve exactly this problem by collating together all the best bits of advice, best practises, resources and whatever else seems relevant.

I found this on Reddit /r/PHP and there was a massive fight about PSR-1 and PSR-2 with the usual "You'll pry allman brackets from my cold dead fingers" bullcrap, so I jumped in and send a pull request to fix up the FIG explanations. Then I kinda got hooked, and I've sent in enough pull requests to get push access and my name on the footer. Cheers Josh!

It has grown exponentially since he set it up and there has been a constant stream of issues, pull requests, comments and improvements. Today it had tweets from Smashing Mag and Gina Trapani (from Lifehacker) and a bunch of other folks are happy to see it and so am I. It's a great resource that focuses very much on how to do things properly.

The main focus here is that PHP 5.4 is a real option, and you should be using it. The latest bout of "PHP 5.4 sux" comments going around are mainly focused on what PHP 5 was. I am forced to work with PHP 5.2 for distributed apps as there are still about 20% of PyroCMS users on that branch. Only about 3% are on PHP 5.4 even though it's nearly half way through its lifetime! Hosts are fun. But while I am stuck on this version, most people aren't. If you are building for clients and you have enough sway then set them up with PHP 5.4. Just tell them its more secure, or faster, or cheaper, or more "social" - whatever you have to say to make them go for it.

It drives me mad on a daily basis that I have to use this archaic version of PHP because... wait for it... PHP 5.4 is awesome!

PHP 5.2, 5.3 and PHP 5.4 all represent MASSIVE jumps forward in the language. Yes we still need primitive types, yes there are still plenty of quirks, but in every single version PHP gets a huge amount better.

Following the advice on this site you will almost certainly learn new things and hopefully it will help new people coming to PHP: The Best Worst Language around.

Comments

Gravatar
Mei

2012-07-10

Great post Phil, and good to catch up on all the developments happenning in the PHP world recently.

It's so inspiring to see big names in PHP working so hard to improve the tools available and providing proper resources from which devs can learn and create.

Keep up the good work!

Gravatar
Calvin Froedge

2012-07-10

Good stuff! Now to rewrite the PHP API to follow these standards and actually get those changes accepted! And all of our frameworks and apps! Without breaking things!

While I'm all for standards, man, that's a herculean task.

Gravatar

2012-07-10

Calvin: PSR-2 is already essentially the exact same style as PHP so there is no problem there. snake_case for functions, camelCase for methods, StudlyCaps for Classes. That is how PHP works, so why is it a concern if PHP components are like that?

Besides, the vast majority of PHP frameworks have already been converted and it wasn't a herculean task. If you can name one that hasn't publicly announced they have switched then I can tell you you're probably wrong about that - but they haven't announced it yet. I know a few who are being very secretive, but I know what they are doing :)

As for your applications, that is down to the framework. If it's a FuelPHP 1.x to 2.0 move then there is a legacy package which aliases old to new. Problem solved.

None of this was about overnight solutions, but the frameworks adopted things way quicker than expected.

Gravatar
Calvin Froedge

2012-07-11

Well, perhaps I just don't know WTF I'm saying. I need to look at the standards and compare to PHP core / extensions / frameworks before I say anything = )

Gravatar
Ben

2012-07-11

Thanks for the update on all things PHP.

It is a shame so much time is spent in conflict and debate, but it's kinda good to know it's alive and kicking.

Though I can't help shaking the feeling that the ongoing conflict of bickering vs rigidity on the PSR-2 recommendations is going to turn it into the new XHTML 2...

Gravatar

2012-07-11

XHTML 2 was rolled into HTML 5 which has seen unanimous adoption. That wouldn't be a bad thing surely?

If by referencing XHTML 2 you mean the project will collapse, I can only see failure happening if the existing projects unimplemented the recommendations and reverted back to their own style guide. Things likes PSR-0 and PSR-1 are fundamental pieces of glue holding together massive applications people don;t just go backwards and forwards between standards on a regular basis. Drupal for example, will not just randomly change back to doing things however they feel like.

The bickering is also not really distracting the FIG itself, everyone is cracking on just fine. I myself am getting distracted due to my foolish misbelief that if you explain things clearly then people will understand. This article should hopefully show that the FIG is not just lost in a crowd of arguments, but now it has a new website and is around for the long haul. It'll get better over time as more recommendations are approved and mature.

Gravatar
Ben

2012-07-11

I guess the analogy to XHTML 2 was somewhat also toward the definition of a standard that was over-detailed without really fitting with what the world needed.

But I agree with your points, and it definitely isn't a worthless exercise.

It is a good thing that some of the major players have decided to adopt it but in a sense, if we follow down the example of Drupal, having the makers behind it is only half the battle won if you can't convince the myriad of plugin makers to do the same.

Anyway, whether agreeing or not on some aspects, it is definitely a worthy exercise and a good sign for the "ecosystem".

Future will tell if PSR-2 end up rolled into the future PSR-5 :)

Gravatar
Spudley

2012-07-11

PHPTheRightWay is a really good idea, and definitely sorely needed.

I don't think it's really achieving it's goals as of yet, because the info there at the moment isn't well enough structured or concise enough to be helpful to a beginner -- at least, not when compared to all those short, snappy, but wrong code examples it's competing against. This will come with time (and contributions), but it's not there yet.

A site that I think is excellent, and would make a really good model for PHPTheRightWay to crib from is Javascript Garden (http://bonsaiden.github.com/JavaScript-Garden/). Well thought out, well structured, clear and consise.

Gravatar

2012-07-11

Spudley: true but it's four days old at this point. It's way better today than yesterday. Give it a week or two at least.

I posted this blog so people will look at it and contribute, otherwise it would take even longer to reach maturity. Things don't get to be awesome overnight.

Gravatar
Spudley

2012-07-12

@Phil: Absolutely right. I'm really looking forward to seeing how it grows and progresses.

Gravatar
Bb

2012-07-12

First: the website is great idea. That's my compliment. If you don't like criticism stop reading now.

I have a couple of issues with your blog post. It boiled my egg to be honest. For example, you make the point of everyone running around going "THE MEAN MAN ON THE INTERNET IS TELLING ME I CANT PUT BRACKETS ON A NEW LINE", and then, immediately, follow that with a loaded paragraph: "usable" an unnecessary subjective word, I might think it's not usable, in fact I might think it's anything but usable. Do we want clear things up or confuse and alienate "everyone"? "love their YAML parse", again, unnecessary, and only lends to a "scan", i.e. when a reader realises that what he or she is reading contains useless information, and as such, "scans" the paragraph. Or worse, stops reading altogether. "everything is the same", I don't even know where to begin with that one...

My point, is that, subjective and needless information doesn't help *as much as it would* if you were direct, concrete, and omitted the needless information. Of course, if the blog post is just a bit a fun and not a "mission to help people know what the hell the FIG are up to" then fine, it doesn't matter does it.

I think it was Strunk & White in the Elements of Style who said: why say, "'a period of unfavourable weather set it', when you can say, 'It rained every day for a week'".

Gravatar
Phil Sturgeon

2012-07-12

Sorry. Only. Keywords. Future. Over.

Gravatar
Jason Shultz

2012-07-14

Excellent article. Thanks for some constructive arguments and helping to clear the air. You are doing an awesome job as usual.

Gravatar
Calvin Froedge

2012-07-15

Phil,

This article documents a lot of the inconsistencies in PHP, some of which I had in the back of my mind when I made my first comment:

http://me.veekun.com/blog/2012/04/09/php-a-fractal-of-bad-design/

Of course we can standardize our APIs and Frameworks, but there's still a lot of other work to be done. There are thousands of bugs in the PHP bug tracker (granted many of them may be bogus) and as the article I linked points out, some issues that have arisen from years of sloppy design and directional changes.

I'm certainly not bashing PHP. I cut my teeth on PHP and it's still my most productive language. Standardizing the framework code may go a long way in insulating users from problems with PHP's core, but the vast majority of PHP developers still aren't using frameworks, and when they do, the choices available are overwhelming. In my mind, improving the language itself (and that means *fixing* things, not just adding new features) is the most important thing that could be done to advance PHP.

Whether all the major frameworks use:

if($condition){

}

...or

if($condition):

endif;

...or

if($condition)
{

}

Is really of little consequence compared to some of the other issues. The typehinting and casting will still be error prone and buggy (array) $object. Comparisons will still suck (NULL < -1) (NULL == 0). There will still be tons of half implemented features. Who will fix these things?

One minor point (doesn't even have to be addressed). You said:

"the vast majority of PHP frameworks have already been converted"

I know that CodeIgniter hasn't been converted. What's in the current develop match certainly doesn't match the standards. Fuel does. Aura does. Those are the two I was familiar with and checked. Sticking with the CI style guide or is CI not being converted?

Not looking to start a flame war here, just playing devil's advocate.

Gravatar
Calvin Froedge

2012-07-15

PS. I know some of the things in the article have been addressed already.

Gravatar
Phil Sturgeon

2012-07-23

Calvin: There are certainly a bunch of issues with PHP but focusing on those here is somewhat out of scope. People often say "Whats the point of the FIG? Why talk about PHP standards when you could fix PHP itself?". Well, I don't know anywhere near enough C to contribute. Do you?

There are a bunch of smart people working on PHP and 5.5 is looking slick. We'll have type hinting, getters and setters for properties, all sorts of awesome stuff - and I presume there will be a fair amount of bug fixing happening too.

PHP is a crazy language that gets drastically better with every version. There are even some awesome great discussions happening for features beyond 5.5:

http://news.php.net/php.internals/61325

CodeIgniter is not on the FIG, nobody at EllisLab has made any indication of wanting to be on the FIG and I assume it will not be changing ever, or soon. As you know CI has always been about backwards compatibility and supported PHP 4 for years after everyone else. Rebuilding the entire API and requiring PHP 5.3 is going to destroy the community as it's just too big to steer. FuelPHP can get away with it as the community is smaller, and the change from the existing standards to PSR-1 are not so big.

There are a few frameworks that have a sneaky PSR-X version either complete, or nearly complete with an intention of releasing soon. You'll see :)

Posting comments after three months has been disabled.