This page is no longer maintained — Please continue to the home page at

PHP to Scala, Scala to JavaScript

Web development in Scala has taken another step forward. Alex Ramos tells us about a new open-source software package that has become available to convert PHP code to Scala. While Wolfgang Kühn, a member of the trading development team at ENBW describes how to translate Scala into Javascript. These two open source projects allow you to convert existing PHP application code to a more maintainable Scala and the ability to write rich web clients in Scala too. So now you can more easily convert those old web applications and continue development or build new ones in a uniform more maintainable environment like Scala.

PHP to Scala - Alex Ramos

This isn't a PHP-to-bytecode compiler, but a source code migration tool. According to the website, this is NOT intended as a compiler to make the PHP code "run faster", albeit up to 3.4x faster. It is intended to make the PHP code "go away". The theory is, that since the Scala code is maintainable, any future changes and enhancements to the application should be done in the Scala code itself - rather than modifying the PHP and "re-compiling" to Scala.

The choice of Scala for this purpose was rather interesting. According to the website:

"One might ask: why not target another JVM language such as Clojure, Groovy, Jruby, Jython, or Java itself as the output of the migration tool? The answer is found in the translation complexity. Only Scala has enough syntactic flexibility (such as implicit conversions, operator overloading, triple-quoted strings, and the Uniform Access Principle), to enable a mostly lexical (token driven, as opposed to syntax tree driven) conversion from PHP. The power of Scala is what ultimately enabled the proof-of-concept for this tool to be developed in one weekend afternoon and is also what enables the generated code to remain clutter-free and close to the original, improving readability which is the project's main goal."

The PHP-to-Scala Migration Helper (php-to-scala for short) is bundled with a Scala wrapper around the Quercus libraries, which provide a Java implementation for over one thousand PHP built-in functions, as well as number-handling semantics.

Scala for Clients - Wolfgang Kühn

Wolfgang Kühn, a member of the trading development team at EnBW Energie Baden-Württemberg AG, explains in his talk at ScalaDays how they are able to translate Scala into Javascript using j2js. With this they can now develop both the front-end and the back-end using the power of Scala along with the advantages of static type checking. He says that ENBW trading uses Lift, based on Scala, for their web servers and plan to use Scala for the client instead of Javascript. This ability to create rich web clients in Scala is an important part of their development strategy.

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland