posted by Kroc Camen on Sat 20th Dec 2008 17:54 UTC
IconIBM delves into what's new in PHP 5.3: Part-1 shows you the changes to the object-orientated capabilities, and Part-2 shows you the exciting new possibilities with real closures and lambda functions. ["Read more" for Kroc's personal commentary]

PHP is a language I dislike, but am good at. It is a language that, as long as you stay away from certain parts of it, you'll be safe and it works well. It can even be beautiful in some rare instances.

The very hackish nature of PHP does allow for rapid development, but it's eclectic design makes it a minefield for anybody who isn't personally motivated and regimented about clean, safe and sensible coding.

The new improvements in 5.3 only continue the junk-shop eccentricity of the language. Great when you know you want these things and how to use them, a pain if it's all new to you.

PHP can claim to be "Object Orientated" until the cows come home, but the fact of the matter is PHP's native objects and commands are still painfully procedural, trapped in a stasis field of backwards-compatibility.

Whilst a new high-speed fixed array is nice, the project is trying to solve it's problems by bundling a library rather than entering this stuff into the core syntax. I honestly don't want to use a bolted-on library and to have to instantiate classes for something I would much rather be able to do properly inline with the native syntax array (...). Having to use a library makes for syntaxically unpretty and elongated code, the spawning of more and more one-shot classes and variables until your code starts looking like VB6 meta-programming.

Closures:

The most beneficial, useful and almost elegant addition though is closures. The ability to create inline functions like Javascript. It's messy, it's confusing for beginners, it's hackish -- but like Javascript, it makes for rapid development, rapid prototyping and rapid rewriting.

PHP currently can create lambda functions via create_function, but this accepts the function code only as a string, meaning that it's not practical for anything more than one or two lines of code as you have to escape the string. Text editors can't syntax highlight this or provide any additional interactivity with this horrible function-text-blob.

Closures change everything. Now it is possible to write array_map iterators inline, of any length, as anonymous functions! This brings the sort of power Javascript developers have with Prototype and jQuery right into the PHP syntax.

Closures alone is going to make a massive difference to the way I code PHP. It's going to allow for much tighter code across the board. Developers will be able to use a lot less ancillary and pseudo-private functions polluting the global namespace.

Final Thoughts:

PHP is looked down upon in many circles. It's the ugly duckling, but with all the popularity. Javascript's terrible lack of rigour and overal hackish nature is not looked down upon, instead it's adored as the language of web 2.0. The roll out of PHP 5.3 will finally give PHP a swing away from "doing things right" as far as Ruby and Java are concerned, and toward the more quirky, rapid, web 2.0 style of Javascript development.

PHP already suits Javascript developers well, now it really will suit them down to the ground.

e p (4)    41 Comment(s)

Technology White Papers

See More