What if PHP were Completely Rewritten to be More Elegant?

PHP gets a lot of flak for some of it’s strange idiosyncrasies. It’s lack of consistency about argument order (needle then haystack in str_replace,  haystack then needle in strstr) and function names (stripslashes vs strip_tags) are particularly head-scratching examples. This partly comes from PHP’s roots; it’s basically a wrapper around existing C functions, and it pretty much mirrors them for convenience. (The MySQL functions are a good example of this.)

Now I like PHP. It’s not perfect, but it gets the job done. I like it’s C-style syntax, and it’s installed everywhere. Python and Ruby lack that kind of support, as well as having syntactical quirks that just bother me. (Python’s lack of braces is icky, and Ruby’s syntax, though interesting to study from a distance, is a bit too weird for me to wholeheartedly adopt.)

What if there was a way to fix PHP, bringing in some of the awesomeness of Python and Ruby while still retaining support for existing software? I’ve had this idea simmering for awhile that a major effort could be made to restructure the language.

I’m thinking of the “everything as an object” approach, like in Python and Ruby. Instead of strtoupper($mystring) you would have $mystring->upper(). Parameters would be better standardized, that namespace character would be replaced…

But what about backwards-compatibility? Here’s the clever part: the developers would leave dummy functions that would just return the value of the new, more object-oriented function. For example:

function strtoupper($a) {
    return $a->upper();

Having an alias to each of the old-style functions would make it possible to maintain support for legacy scripts, at least for a couple of major versions.

Of course, this would probably never happen. Unless someone were to fork PHP, which might create more problems than it would solve…