News Archive
PhpRiot Newsletter
Your Email Address:

More information

A New Paradigm Rises to Save the Modern Web

Note: This article was originally published at Planet PHP on 1 April 2012.
Planet PHP

A New Paradigm Rises to Save the Modern Web

Programming on the web has come a long way since the wild-west early days of the 90s, and nowhere has this been more evident than in the PHP community. The earliest "apps" made with PHP were little more than some odd scripting bits that helped web pioneers and hobbyists to more easily maintain their html websites. At the turn of the century, larger, procedural PHP apps started to pop up that would eventually change the web as we knew it. Less than a decade later, the widespread adoption of object-oriented programming throughout most web development communities had led to some of the most sophisticated triumphs of software engineering (or hackery) in history.

But just as procedural coding proved insufficient for developing the types of applications that the consumers of the web demanded, the usefulness of object-oriented programming is rapidly reaching its limits. Object-oriented programming ultimately results in highly complex, bloated, and inconsistent code bases that cannot sustain the growing demand they will no doubt receive. Once an object-oriented app reaches a certain mass, those problems begin to create cracks in its very foundation.

To free us from these constraints, some look to new systems that boast event-driven, functional foundations such as node.js. Communities behind these systems make bold claims about the impact they will have on the web of tomorrow, but while this approach certainly has its benefits, it suffers from the very huge obstacle of being completely incompatible with their existing app architectures. To truly revolutionize the web as a whole, a new system or paradigm must allow users to incrementally update their existing apps and workflows.

Fortunately, there is now a new paradigm that originated within the PHP community that is rapidly changing the way we develop web and mobile apps. Array-oriented programming (AOP) combines all of the structure of object-oriented systems with the ease-of-use and efficiency that could exist in procedural apps, and it does so in a highly consistent way. Best of all, it can be done in any programming language that supports arrays, and it can be used to build entirely new apps or even incrementally refactored into existing apps regardless of whether they were procedural or object-oriented to begin with.

Array-oriented programming is based on one driving principle, an entire program structure and flow is defined as an array. It really is as simple as it sounds.

AOP is not a new concept, but it is just now gaining traction in the web development community. There are countless articles scattered across the web that go into great detail about the technical intricacies of this revolutionary paradigm, so I won't bore you by driving in all of those same points. Instead, let's take a look at a complete array-oriented program:

$app = array(

'session' = array(), 'request' = array('method' = 'GET', 'uri' = '', 'data' = array()), 'response' = array('body' = '', 'headers' = array()), 'errors' = array(404 = function(&$request, &$response) { $response['body'] = '404 Not Found'; $response['headers'][] = 'Status: 404'; }), 'routes' = array('GET /' = function(&$request, &$response, &$session) { $name = isset($session['name']) ? $session['name'] : 'World'; ob_start(); // not shown, but your standard php template include '../template/home.phtml'; $response['body'] = ob_get_contents(); ob_end_clean(); }, 'POST /' = function(&$request, &$response, &$session) { if (isset($request['data']['name'])) { $session['name'] = $request['data']['name'];

Truncated by Planet PHP, read more at the original (another 5614 bytes)