Skip to main content

Crouching Javascript, Hidden PHP [3]

By Harry Fuecks



Free JavaScript Book!

Write powerful, clean and maintainable JavaScript.

RRP $11.95

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 ;))

Harry Fuecks is the Engineering Project Lead at Tamedia and formerly the Head of Engineering at Squirro. He is a data-driven facilitator, leader, coach and specializes in line management, hiring software engineers, analytics, mobile, and marketing. Harry also enjoys writing and you can read his articles on SitePoint and Medium.

Latest Remote Jobs

Integromat Tower Ad