By Harry Fuecks

Crouching Javascript, Hidden PHP [3]

By Harry Fuecks

It’s alive!

Here’s the short explaination…

Let’s say you have a PHP class that looks something like;

class Math {
function add ($x, $y) {
return $x + $y;

You can now use this from Javascript like;

var m = new math();
alert (m.add(2,2));

No need to think about the underlying mechanism / encoding (as discussed earlier).

A complete example can be seen by looking at the following;

PHP Source for a “server” – this is what you’d write server-side

The Javascript Client Code generated automatically from the PHP server (note that can be “compressed” with the switch of a PHP constant)

The Client (View > Source for Javascript) – this is all you’d code by hand client side.

output from server – example of what the Javascript client get’s back from PHP; a string (for eval) containing an anonymous function which itself contains an array. Much more compact than XML with no issues in parsing (although not very human friendly. The tail of the URL corresponds to the /class/method/ names.

Download all this in the first (alpha) release from here.

Phew! Now that’s out of my system, can catch up with email etc (before Kev murders me ;))

The most important and interesting stories in tech. Straight to your inbox, daily. Get Versioning.
Login or Create Account to Comment
Login Create Account