Category Archives: Coding

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…

Dive Into HTML5

Looking to bring your HTML skills up-to-date, now that HTML5 support is growing in modern browsers? Mark Pilgrim has a nice online book by the name of Dive Into HTML5 that covers most of the big new things. It is also available in print,…

Tempo: A Tiny JSON Templating Engine

Tempo is a 4kb JavaScript library that renders JSON into an HTML template. Your script can take something like this… …and populate it with JSON data from the Twitter API, which you could load with a couple lines of jQuery. It works with browser…

Try Ruby: A Clever Interactive Programming Tutorial

Teaching a newbie how to program is a difficult task, whether you’re writing a book, recording a screencast or teaching a class. Similarly, it’s a bit of a hassle for someone who is proficient with one or two languages to pick up a new…

Syncing Content With HTML5 Video or Audio

This is one of the coolest Smashing Magazine articles I have seen in awhile: Syncing Content With HTML5 Video. Using the generic HTLM5 video and audio elements and a bit of JavaScript, the timeupdate event in particular, you can synchronize script events to the…

Evil JavaScript Trick: The History Nuker

Remember back in the bad old days of the internet, when pop-up ads and other annoyances were around every corner? Some sites, by some flawed logic, would decide that you didn’t really want to leave their website when you clicked the Back button and…

Variable-length Argument Lists in PHP with func_get_args()

Have you ever wanted to write a function in PHP that would accept a varying amount of arguments rather than requiring ones arbitrarily hard-coded? I can’t think of a reason why you would off the top of my head, but I know I’ve wished…

GluePHP — A Spartan URL Routing Framework

For larger PHP projects, it’s a good idea to use the Model-View-Controller pattern and URL routing to organize things a bit more logically and make the code easier to update in the future. Frameworks like CodeIgniter, Kohana and CakePHP do this, but they can…

PHP Error Suppression Symbol

Have you ever seen a PHP script where a line is prefaced with a “@” symbol? Ever wonder what it was for? The at symbol in PHP is the error suppression operator. Any expression with you use it with will never throw an error,…

CodeIgniter 2.0 Released: No More PHP4 Support!

EllisLab just released version 2.0.0 of the CodeIgniter PHP framework. There are a few interesting new additions, such as a cache driver with APC and memcache support, the option to let controller handle 404 errors, and the deprecation and removal of Scaffolding. Perhaps the…