tags:

views:

128

answers:

3

...like GWT, but PHP as output (instead of Javascript)

So I can code in java while the webserver executes PHP.

--

I don't want to mix Java with PHP. In runtime there will be only PHP, but at compile time there should be only Java. It is like GWT does. it takes java and converts it as Javascript for the browser.

This is just to take full advantages of a full-typed language at compile-time.

+1  A: 

What's the reason you can't just run Tomcat or something?

Unless there's a specific reason you cannot use a Java server, it seems that doing this would be pointless and a big hassle. Java and PHP are so different that I can't imagine a subset of functionality that can be translated from one to the other would be at all useful.

thomasrutter
Java and PHP are quite different beasts. Ex. PHP has no concept of static state between web requests. All the local memory used after an http request is torn down. In Java you have static variables, can use factories etc.
seand
State between requests can be maintained using ACP. Why can't you use factories in PHP?
nhnb
Of course you can use factories in PHP. However, holding state between will be a problem, although not impossible.
Techpriester
+3  A: 

PHP and Java are very different beasts. Translating Java to PHP is likely to be so technically difficult that it next to impossible to implement for a subset of Java / JEE functionality that was large enough to be worthwhile.

You'd do better either:

  • learning and using PHP,
  • implementing your entire server in Java, or
  • using a bridge that allows you to call into an embedded JVM from PHP; for example, palava (thanks @Willi).

EDIT

@nhbh comments thus:

PHP is very similar to Java nowadays. It supports object orientation, can be executed from the command line without web request and can maintain a global state across requests using ACP. So writing a cross compiler from Java to PHP would be rather easy. But of course it is a huge amount of work to port API calls, so I doubt it is worth the trouble.

There are obvious similarities between Java and (OO) PHP. But there are fundamental differences as well that make translation problematic:

  • There are fundamental difference between Java primitive / builtin types and their PHP equivalents. Java integer and floating point types don't map directly because of range considerations. Java Strings don't map because PHP strings use 8 bit characters. These will cause problems getting simple Java code to work correctly when translated to PHP.

  • Java's threading, synchronization and the underlying memory model are probably untranslatable.

  • Java dynamic classloading, reflection, security and object serialization APIs are probably untranslatable. (In the last case, I would claim that a mapping is only complete if it produces byte-for-byte compatible serializations.)

  • Creating bridging APIs for the breadth of the Java APIs would be a huge task.

  • Interfacing with native PHP is likely to cause problems; e.g. Java calling PHP and vice versa, and Java code dealing with objects/values created by PHP code.

In summary, a full-function Java to PHP translator is probably next to impossible. The best you could hope to achieve would be a partial translator that only worked for a small subset of real-world Java code.

Stephen C
PHP is very similar to Java nowadays. It supports object orientation, can be executed from the command line without web request and can maintain a global state across requests using ACP. So writing a cross compiler from Java to PHP would be rather easy. But of course it is a huge amount of work to port API calls, so I doubt it is worth the trouble.
nhnb
Here is a reference: http://palava2.org/why.html
Willi
A: 

Google finds http://www.instruction.com.au/java2php/ but the webserver is unavailable right now.

nhnb