Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Embedded Javascript interpreter for php

Is there some api available for embedding javascript in php - something similar to Jint for .NET.

I would like to allow user to customize workflow by being able to access limited php classes and methods that can be run at server-side.

User writes a code block that gets executed later... for example, js/ecma script code like ...

if (Contact.Age < 12){
  Contact.setEligibility = false;
}
else{
  Contact.setEligibility = true;
}
like image 835
Cheen Ju Avatar asked Nov 21 '25 20:11

Cheen Ju


1 Answers

There's a pseudo-Javascript interpreter called 'phpjs' (php functions implemented in javascript), which I happen to know about. And a fully syntax compatible JS interpreter (written in pure PHP) called Javascript for PHP5: http://j4p5.sourceforge.net/ - implements the JS language, not the DOM or much functions.

If you want a full-fledged and "real" Javascript runtime, then there is a PECL extension for that. http://pecl.php.net/package/spidermonkey (requires custom compiling PHP interpreter).

like image 88
mario Avatar answered Nov 23 '25 09:11

mario



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!