Skip to main content

Getting started

Quick installation

We provide a Giter8 template, which you can apply to create a new project with Scala.php already set up.

sbt new scala-php/scala-php.g8

Installation (less quick)

info

Scala.php only supports Scala 3.3.0 and above.

warning

Scala.php is still deep in development. Many features of the Scala language currently fail to compile.

Adjust your expectations accordingly.

In your project/plugins.sbt:

project/plugins.sbt
addSbtPlugin("org.scala-php" % "scala-php-sbt" % "0.1.1")

Now, you can enable the plugin on the modules you want to compile to PHP:

build.sbt
val main = project
.settings(scalaVersion := "3.4.0")
.enablePlugins(PhpPlugin)

Usage

In order to start building with Scala.php, simply create a Scala file in the source root of your project and start writing Scala code:

src/main/scala/Main.scala
object HelloWorld {

def main(args: Array[String]): Unit = {
val greeting = "hello"
println(s"$greeting world!")
}

}

Now, you can compile and run the code with the PHP interpreter.

info

You must have a PHP interpreter available. By default, the PATH is used. To specify a custom interpreter, see Configuration.

sbt run
Output
hello world!

Check out the examples for more complex use cases.