Tuesday, November 6, 2007

PHP is Funny

There are a lot of things that I like about PHP. For instance, the addition operator (+) is different from the concatenation operator (.). This prevents the common ambiguity in weakly-typed languages of "'1' + 1".

PHP has a lot of quirks though - due to its highly "organic" development. Variable variable names are a prime example:

$a = 'hello';
$$a = 'world';
echo "$a $hello"; // prints "hello world"

Confusing, no? Also, the object-oriented stuff seems tacked on (probably because it was tacked on) and the function to escape text so that it is HTML-safe is called "htmlspecialchars()". For a language whose main function is to output web pages, couldn't they have thought up a shorter function name?

1 comment:

allamericanboi said...

I, too, love PHP, because I really don't think there is anything that can't be done with it. Maybe some things could be done more efficiently elsewhere, but otherwise the possibilities are endless.

I always do my variable variables like this just to keep myself sane: ${$a}, which of course also helps when you want to build a variable out of a string and another variable.