SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Enthusiast
    Join Date
    Aug 2000
    Location
    Bay Area, CA; (Pasadena, CA this fall)
    Posts
    61
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Java to PHP translation

    I've been working on a Java to PHP translater. To php5, it's rather simple, because much of the syntax is very close.

    The reason I started working on this:
    -I like static types (much easier in the IDE when you can hover over the identifier and actually see the type, click to see type-definition, etc)
    -Java IDEs are better than anything available for PHP (I've been using Eclipse for my Java coding recently)
    -PHP5 is taking a loooooong time coming out

    Right now, it's geared to translate to PHP5. I'm pretty sure that if I needed to, I could have it translate to PHP4.
    (This is also a benefit to this translater; if you had to deploy your project before the host has PHP5, you at least get code that's more readable; the translater will do all ugly stuff such as changing object variables to references (buncha &'s don't look too pretty) )

    1 problem I've realized is that Java has no global scope really. So, I'm just going to append at the end of each file with a global class a call to the global class' main function.

    One downside to this approach is that debugging would have to be done in PHP. Then, once you found the bug, you would have to see where the bug is in the Java code.

    Does anyone else think this is worthwhile?

  2. #2
    SitePoint Wizard Chris82's Avatar
    Join Date
    Mar 2002
    Location
    Osnabrück
    Posts
    1,003
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Funny, today I downloaded phpedit and while it was not bad, it does not yet match with eclipse. Then I thought it would be great to have a program which translates code written in eclipse (using Java's syntax) to PHP.
    I think debugging is not that a big concern for me personally. I never really had the reason to do this. But for some people it can be useful.

    So, I think this very worthwile and I would be interested in your progress in this matter.

  3. #3
    SitePoint Wizard gold trophysilver trophy
    Join Date
    Nov 2000
    Location
    Switzerland
    Posts
    2,479
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Does anyone else think this is worthwhile?
    Certainly. Personally see it more useful to convert existing Java libraries rather than working with an IDE, for example http://xmlc.enhydra.org/. Could become a mammoth project though - what's you're strategy on calls to the Java library?

  4. #4
    SitePoint Zealot
    Join Date
    Jun 2003
    Location
    Middle / East TN
    Posts
    127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    While your at it, you might as well throw in a PHP5 to PHP4 converter, many people would be happy
    There are 10 kinds of people in this world,
    those who can read binary and those who can't.

  5. #5
    SitePoint Enthusiast
    Join Date
    Aug 2000
    Location
    Bay Area, CA; (Pasadena, CA this fall)
    Posts
    61
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    For calls to the Java library, I'm a bit undecided at the moment...
    Currently, I map functions such as StringVar.length() to strlen($StringVar) and the same with arrayvar.length to sizeof($arrayvar)

    For other needed classes, I was looking at the other thread here called "Java API as base for PHP library"; it appears nothing already exists that matches Java's library.
    I might end up writing my own PHP classes. I think the only needed ones: Iterator, Collection, HashMap, ArrayList

    It's already a bigger project than I thought at first though... just adding $ to a variable was easy. I've only realized now that I basically have to do a full compiler that stores methods and classes, inner classes, etc.

  6. #6
    SitePoint Wizard gold trophysilver trophy
    Join Date
    Nov 2000
    Location
    Switzerland
    Posts
    2,479
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    As already mentioned, perhaps more worthwhile is a PHP 4 <==> PHP5 converter. Also check out Phing which is like Java Ant - might be handy tool for developers to write scripts in PHP5 and have them quickly converted to PHP4, each time they make a change. With PHPDoc style comments you can probably go the other way as well.

  7. #7
    SitePoint Guru
    Join Date
    Nov 2002
    Posts
    841
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by webhappy
    It's already a bigger project than I thought at first though... just adding $ to a variable was easy. I've only realized now that I basically have to do a full compiler that stores methods and classes, inner classes, etc.
    Its a huge project and probably not worth it.

    If you like java IDEs and you like Java static typing, why not just use Java?

  8. #8
    SitePoint Enthusiast
    Join Date
    Aug 2000
    Location
    Bay Area, CA; (Pasadena, CA this fall)
    Posts
    61
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Basically, I only know how to deploy for PHP.
    Main reason why: PHP is free to deploy and much more widely available. (Java might also be free, but it's definitely not as easy to find hosts with it)

  9. #9
    SitePoint Enthusiast
    Join Date
    Aug 2000
    Location
    Bay Area, CA; (Pasadena, CA this fall)
    Posts
    61
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's also not that bad, if I force the programmer to NOT use features not already supported by Zend 2:
    no inner classes, no namespaces, all classes must be uniquely named


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •