Made PHP and JS versions equal, fixed bugs, all tests should pass

Signed-off-by: Nick Brook <nick@rmpenterprise.co.uk>