php-js 0.1.2 review

Download
by rbytes.net on

php-js application is an experimental PHP extension which embeds the Mozilla SpiderMonkey JavaScript engine into PHP. Installation

License: The PHP License
File size: 136K
Developer: Omar Kilani
0 stars award from rbytes.net

php-js application is an experimental PHP extension which embeds the Mozilla SpiderMonkey JavaScript engine into PHP.

Installation and Usage:

A simple ./configure; make; make install should do the trick. Make sure to add an extension=js.so line to your php.ini/php.d. Note: you need to install libjs first. If you're using a Redhat-esque system, you can use the SRPM provided above, else, use the TBZ.

Then, just use js_eval to evaluate your JavaScript. js_eval returns the value returned by the JavaScript interpreter to PHP.

For example:

js_eval("var a = 123;");
js_eval("var b = 456;");

$c = js_eval("[a, b];");
echo "a is ".$c[0]."n";
echo "b is ".$c[1]."n";

js_eval("var sum = function(x, y) { return x + y; }");

$d = js_eval("sum(a, b);");
echo "The sum of a and b is ".$d."n";

Would produce:

a is 123
b is 456
The sum of a and b is 579

js_eval takes an optional boolean argument, assoc, which returns objects as associative arrays instead of PHP objects.

The php-js execution environment provides two built-in JavaScript system functions:

print
gc

print outputs its argument to the php output stream.

gc forces garbage collection within the JavaScript environment.

What's New in This Release:
A session shutdown issue has been fixed.
There is better handling of null objects.

php-js 0.1.2 search tags