SNAP stands for shared namespace application programming. It’s a small PHP utility I wrote that allows you to write functions in PHP and wrap them up into javascript modules. This allows you to essentially call server side code from the browser without fussing with AJAX.

There’s still plently of work for this project. PHP runtime errors transition somewhat gracefully to javascript, but parse exceptions do not — in other words, a syntax error will throw a major wrench in the works.

Let’s look at some PHP!

 
// file name: bar.php


function getUserInfo($username){
   // do some server side operations

}
 
// file name: bar.php

// file name: foo.js.php


// create a new module.

$module = new SNAPModule("SNAP");


// register the function bar() in bar.php as foo.

$module->registerFunction("foo", "bar", "bar.php");


// write JS to the page.

SNAPTrigger($module);

Now let’s look at some HTML!

 
// file name: index.html

<script type="text/javascript" src="foo.js.php"></script>
<script type="text/javascript">
  // this function was written in PHP.

  var something = SNAP.foo("some-user-name");
</script>