Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best way to convert an existing php class into Java?

Tags:

java

php

I have been tasked with converting several php classes into java classes, which is quickly becoming a nightmare for me. I understand the basic language structure, it being similar to C. It is all of the function calls and class calls that seem to go nowhere and the fact that a var can be declared in the !middle of an expression! that is spinning my head, oh and the fact that there is zero "0" documentation.

What is the best method (and/or) tool (and/or) reference material to convert the php into java code?

edit: There is 3 reasons that I am having to convert the php to java.

  1. The usual reason, my boss told me too.
  2. The php is too slow, it is taking minutes sometimes to run a request to the server.
  3. php is a nightmare to scale and maintain.(at least for us strong typed language types)
like image 289
WolfmanDragon Avatar asked Dec 12 '08 19:12

WolfmanDragon


2 Answers

You ask about best practices. I believe a good practice in your case is the approach pleasantly presented by theman: using an automated tool will probably give a bad result: garbage in, garbage out...

You have the code: analyze it, in its broad lines if necessary. And re-create it in Java. It might be time-consuming, but not necessarily worse than by doing blind conversion. And you can document on the way, and perhaps use this analysis to find the problematic parts.

like image 181
PhiLho Avatar answered Oct 28 '22 12:10

PhiLho


A human is the best tool.

I would try to rewrite the php to remove most of the php features to something C like. Then you'll have an easy time rewriting in Java.

But I need to ask, why do you need to convert the php? Can you not wrap the php into something callable from Java? This way you won't add any errors while converting it.

like image 36
Pyrolistical Avatar answered Oct 28 '22 13:10

Pyrolistical