3

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;
}
1
  • I am afraid to directly expose script execution to the client. Didn't really evaluate that as an option. Thanks for the thought. Commented Dec 21, 2010 at 4:16

1 Answer 1

5

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

Sign up to request clarification or add additional context in comments.

2 Comments

worth pointing out that both the above are alpha releases, so not production quality. j4p5 looks interesting but appears not to have been updated in several years; project may be dead. The spidermonkey one is more recent but the homepage link is dead. I don't think I'd want to use either for anything serious.
Thanks, mario. Appreciate your help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.