Tuesday, March 26, 2013

PHP is (no longer) Terrible

The Pitfalls of PHP 4

I've been away from PHP for a long, long time.  We're talking the ancient days of PHP 4, right after the turn of the century.  The last real time I used PHP, besides hacking the random Wordpress plugin or something for clients, was a Blackjack app that featured AJAX during the early GMail days when it was kinda a big deal.

For the app I of course had objects, like a Card with properties like suit and rank, and a Deck with methods such as shuffle().  At the time, in PHP 4, the capability of objects really was not fully implemented.  There was no real difference between protected and private variables, only the most basic of inheritance had been implemented, and in the end an object was just a glorified global; the class just a way to encapsulate an instanced set of variables and functions.

The Improvements of PHP 5

It really seems like yesterday; so much so that in fact that it feels like we still need to maintain compatibility of web applications for that fossilized version.  And thankfully that feeling is unfounded.  PHP 5 has been out for years and years now, so long that if a web host hasn't done the basic maintenance to update it in that time, then there are bigger problems to deal with.

The latest versions of PHP 5 have really allowed the language to evolve from just the toy of script kiddies to a language that can be seriously considered by professionals. The strong object-oriented features, namespaces, and function lambdas that always seemed to be missing are just a few of the really cool things to come along.  The standard library is vast and full of functionality, and PHP's documentation is really good.

PHP code is also really fast to execute, with the parser somehow being performant today than ever before even though it is far more capable than the past.

Modern 2013 PHP Frameworks

From this we have the introduction of the modern PHP framework.  One of the reasons I still prefer PHP for web development is that it's everywhere.  Most of the job listings for freelancers and full-time professionals are for PHP.  You can be really good at developing web apps in Ruby or Python, but at the end of the day you're eventually going to have a client who's web host has minimal support for the languages and you'll have to pick up a PHP framework.

Now I am from the school of thought that popular is not always better; if it were so I'd be writing ultra-nested bracketed jQuery calling to PHP files mixed freely with HTML and script like 80% of all the web applications I was ever hired to fix up.

With the addition of things such as namespaces, frameworks are now more extensible than ever.  Plugins and modules are first-class citizens.  The architecture of MVC has moved into the realm of event-driven programming, something those of use from the desktop programming world are used to.  The better frameworks also decouple things like abstract objects into a series of dependency injections., further facilitating plugin architecture and reusable code.

The Future of AJAX Applications

One thing that needs to be done is better integration with AJAX.  We need some kind of better, more RESTful solution for AJAX applications.  Where if the request is an AJAX request, it will only return a view of the content and not the entire site layout, and then you can simply replace an HTML div.  Fortunately this is easy to do in the best PHP frameworks such as Laravel and Zend.

We need to push the adoption of things like pushState() if we ever want to go to a truly AJAX experience.  This can be done by introducing a script (whether server or client-sided) that displays a message to users with outdated browsers that it's time to update their browsers.  Users with outdated browsers are also at increased security risk, so major websites such as Facebook and Twitter should adopt it as well.

No comments:

Post a Comment