In preparation for moving gracefully into a future with more and different types of code in it, I finally upgraded my tired old computer with a decent ASUS mobo, a core i5 3570k, 16GB of RAM, and a modestly sized but speedy Crucial SSD. Size, it turns out, does actually matter. Nevertheless my new system runs cool and sleek and can be stress-testing apache2 in a VMWare Player instance without my even noticing it while I play Minecraft.
(Just kidding about Minecraft! I’ve logged 25 minutes in the last 8 months. Once I’ve uninstalled Minecraft again and get Visual Studio and Eclipse installed, I will feel ready for anything.)
I also started shifting my web host from HostMonster to an entry-level ServerGrove VPS offering because, let’s be fair, 5 second load times for a small wordpress site are bad PR. My hair does enough bad PR for me already — I really don’t need any more.
While I was poking around on my VPS, I found that I had PHP 5.4 installed. I finally got around to checking out the new features for 5.4 and was delighted at the prospect of exploring them! Here’s a sampler of what’s on tap:
- Short array syntax. PHP’s hashed arrays, a built-in type that radically predates their standard object implementation, are enormously useful but have, until now, been burdened by an inexplicably verbose and obscure notation.
$data = array ( 'key1' => 'This is a text string', 'key2' => 6, 'key3' => new ThingyMcThing(), // delicious trailing comma to ease future additions to the array );
$data = [ 'key1' => 'This is a text string again', 'key2' => 7, 'key3' => mcThing.factory.getMcNugget(), // nom ];
And it feels better — it feels right.
- And here’s the best saved for last: effective in this version of php, <?= will (wait for it) always work regardless of whether short_open_tags is enabled or not. Short open tags have never provoked the same sort of heated dialogue as code indenting idioms or editor choice, but they have been debated deeply and at length. And while the arguments against short open tags are compelling, the utility value of inline substitution (specifically, the <?=$variable;?> form) is simply enormous. Given the amazing quantity of open source libraries, frameworks, and templating engines, it’s easy to forget that PHP is *itself* a templating engine. Indeed, disabling short_open_tag functionality makes using raw PHP template expressions cumbersome to produce and grueling to decipher (particularly with !@#$ing alternative control syntax). This particular choice in 5.4 is ingenious. XML can keep its <?, but <?= belongs to PHP. It’s the perfect middle ground.Glyph by glyph, I’ve always thought of the abbreviated open tag assignment like this:
< // open a channel
? – pass through the barrier from HTML space into PHP space
= – assign. Helpful that the equals sign, when compressed between ? and $, looks like a pipe or a connector.
$variable – push the content of $variable outside of PHP space, through the assignment pipe, into HTML space.
; – end of PHP expression
? – pass through the barrier from PHP space to HTML space
> – close channel
Of course, the symbols are entirely arbitrary and have no such intrinsic meaning — I don’t mean to say that they do. But we humans naturally excel at populating the unspecified with our own imaginations, and furnishing arbitrary symbols with meaning. We do it so well that we spend most of our lives suspended in a web of meanings that we have created ourselves and transmitted culturally. It’s great!
I am looking forward to a new mode of existence in the not too distant future. As a result, I’m excited about new things! PHP is a messy, pragmatic language, but I’ve always found it to have a sort of neanderthal vitality to it. It’s a good place to start =)
Addendum & Important Caveat
“Technologyland” should not be confused with “Tomorrowland.” Technologyland is cool, it really is. But it isn’t particularly colorful, has very few mushrooms in it, and generally does not smell of body odor.