Yet Another Stupid Perl Versus PHP Rant
Especially because of all the work I’ve been doing in Drupal, I’ve switched most of my development efforts away from Perl solutions and started working mostly with PHP. The «Perl versus PHP» flamewars on the Internet are all over the place and usually full of nonsense. I really don’t want to add to that. In fact, I’m pretty pleased with PHP. The language has come a long way since it’s days as PHP/FI. I’ve come to appreciate its variable scoping scheme, which caused me fits when I first started porting code from Perl to PHP. If nothing else, it keeps me from typing «my» every time I want to declare a variable. Seriously: today default scope being global seems like a horrible design decision. But I digress.
Here’s today’s PHP gripe: if PHP is supposed to be the language for building Websites, where are the functions to automatically make HTML form (and other) elements? I’m spoiled by Perl I guess, but the fact that I can say I’m spoiled by Perl should be a slap in the face of all those out there looking down their ignorant PHP noses at Perl Web developers. When in Perl I want to create a selection box (pull-down menu), I take an array and an associative array and plug it in to one of the CGI.pm
methods:
$q->popup_menu(
-name => 'tour',
-values => \@tourlist,
-labels => \%tours );
It’s meaningless without knowing what data is in the %tours hash and the @tourlist array, but just bear with me.
With PHP, there’s no such library of handy HTML-generating methods. I’ve looked. I don’t understand why no one thinks it’s important. I know that HTML code is pretty easy, but the closest equivalent to the above in PHP goes like this
<select id='tour'>
<?php
foreach ( $tours as $tourid => $label ) {
?>
<option value='<?php echo $tourid; ?>'>
<?php echo $label; ?>
</option>
<?php
}
?>
</select>
…all right, that’s not the end of the world, but it takes two actual skillsets and some thought to construct, not to mention the code is more difficult to maintain. If you want to update your code so that the HTML follows some new coding standard, using the module you can change the options for generating the HTML, and suddenly see your changes in effect everywhere. Even using automatic search and replace you can’t do that with raw HTML code unless you are really, really good about writing consistent code.
It’s just me griping. I still like PHP.