11

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!

hippietrail
  • 15,848
  • 18
  • 99
  • 158
aurora
  • 9,607
  • 7
  • 36
  • 54
  • 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 – Christoph Jan 03 '10 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. – Ray Toal Aug 03 '11 at 16:59
  • 2
    Yes, I wrote one: https://gitlab.com/kornelski/babel-preset-php It produces readable source with approximate semantics. – Kornel Jul 29 '17 at 16:00
  • @Kornel thanks! that looks quite interesting! – aurora Jul 30 '17 at 22:14
  • maybe help you this link [awesome opensource transpilers](https://awesomeopensource.com/projects/transpiler) – Ion Stefanache Nov 21 '20 at 09:52

2 Answers2

10

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

justspamjustin
  • 1,730
  • 3
  • 19
  • 30
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

alemjerus
  • 8,023
  • 3
  • 32
  • 40
  • 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 http://haxe.org/ which can compile to both PHP and JS might be a better solution – Christoph Jan 03 '10 at 16:28
  • thanks -- i'll have a close look at both, harmony and haxe ... – aurora Jan 03 '10 at 16:58
  • 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 ... – aurora Jan 03 '10 at 20:32
  • @harald: if you look at the svn commit feed of harmony ( http://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: http://haxe.org/doc/php/extern_libraries ; if all that's missing from your application is some JS, porting it to haxe will be overkill – Christoph Jan 03 '10 at 22:19
  • i mark this as answered, because this harmony thing seems at least to be a very good starting point for this. thanks you both! – aurora Jan 05 '10 at 07:58