12

i wonder, if there's any transpiler available, which converts (simple) php code to javascript?

what i am not looking for is ajax stuff or javascript libraries imitating php functionality, but i am looking for a translater, which is able to generate javascript code from php code (similar of what google is doing with GWT and the java-to-javascript transpiler).

thanks!

5
  • afaik GWT is a compiler, not a transpiler; transpilers in general aren't terribly useful and will most likely only work for special cases because of the differences in type systems/standard libraries Commented Jan 3, 2010 at 16:04
  • I prefer the term cross-compiler, too, but the term transpiler is starting to get used more and more often these days. We'll see if it catches on. At least in the JavaScript world, I think it just might. But I agree with your sentiment. I tend to think CoffeeScript to JavaScript is a transpiler, but Java to JavaScript, not so much. Others disagree. We'll see what people are saying a year from now. Commented Aug 3, 2011 at 16:59
  • 2
    Yes, I wrote one: gitlab.com/kornelski/babel-preset-php It produces readable source with approximate semantics. Commented Jul 29, 2017 at 16:00
  • @Kornel thanks! that looks quite interesting! Commented Jul 30, 2017 at 22:14
  • maybe help you this link awesome opensource transpilers Commented Nov 21, 2020 at 9:52

2 Answers 2

10

The uniter php to js transpiler can do this: http://asmblah.github.io/uniter/

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

1 Comment

Thanks, this looks already very promising!
1

You can use something like this: http://www.harmony-framework.com/
But notice, that Javascript has lots of security issues PHP avoids. And straight conversion is not always possible for Database-related function calls or some other PHP extensions

5 Comments

my comment to the question applies: eg, harmony translates array($a => 'foo') to {a : 'foo'}; depending on the problem harald is trying to solve, something like haxe.org which can compile to both PHP and JS might be a better solution
thanks -- i'll have a close look at both, harmony and haxe ...
mmm -- harmony seems to be a little outdated -- the webpages last change was in 2008. do you know, if they are still working on it? i think harmony would fit my needs better than haxe, even though haxe seems to be very advanced. but i don't know how i would integrate haxe with my app, because my app is already implemented in php ... only the php->javascript part is missing, which would help speed up development and make things more convenient ...
@harald: if you look at the svn commit feed of harmony ( code.google.com/feeds/p/harmony-framework/svnchanges/basic ), you'll see that development is slow, but I don't think it's dead; the documentation an how to wrap PHP code for haxe seems somewhat... incomplete: haxe.org/doc/php/extern_libraries ; if all that's missing from your application is some JS, porting it to haxe will be overkill
i mark this as answered, because this harmony thing seems at least to be a very good starting point for this. thanks you both!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.