What’s New in PHP v5.3

IBM 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.

41 Comments

  1. 2008-12-20 9:36 pm
    • 2008-12-20 10:19 pm
      • 2008-12-20 11:39 pm
        • 2008-12-21 1:14 am
        • 2008-12-22 5:05 pm
      • 2008-12-21 5:16 pm
      • 2008-12-21 8:14 pm
        • 2008-12-22 2:37 am
          • 2008-12-22 3:10 am
  2. 2008-12-20 11:23 pm
  3. 2008-12-20 11:24 pm
    • 2008-12-20 11:35 pm
      • 2008-12-20 11:40 pm
      • 2008-12-22 5:24 pm
    • 2008-12-21 8:58 am
  4. 2008-12-20 11:38 pm
    • 2008-12-20 11:44 pm
      • 2008-12-21 4:22 am
        • 2008-12-21 6:17 am
  5. 2008-12-21 8:43 am
  6. 2008-12-21 10:42 am
    • 2008-12-22 10:35 am
  7. 2008-12-22 2:54 am
    • 2008-12-22 3:16 am
  8. 2008-12-22 4:09 am
    • 2008-12-22 2:06 pm
    • 2008-12-22 3:44 pm
      • 2008-12-22 5:31 pm
    • 2008-12-22 5:33 pm
  9. 2008-12-22 4:06 pm
    • 2008-12-22 4:39 pm
    • 2008-12-22 4:54 pm
      • 2008-12-22 5:35 pm
        • 2008-12-22 6:11 pm
          • 2008-12-22 8:01 pm
          • 2008-12-22 8:27 pm
      • 2008-12-22 6:12 pm
        • 2008-12-22 9:21 pm
  10. 2008-12-22 6:37 pm
    • 2008-12-22 6:55 pm
  11. 2008-12-23 9:25 am