12.5.1 Getting started with Haxe/PHP

To get started with Haxe/PHP, create a new folder and save this class as Main.hx.

import php.Lib;

class Main {
  static function main() {
    Lib.println('Haxe is great!');
  }
}

To compile, either run the following from the command line:

haxe --php bin --main Main

Another possibility is to create and run (double-click) a file called compile.hxml. In this example the hxml file should be in the same directory as the example class.

--php bin
--main Main

The compiler outputs in the given bin-folder, which contains the generated PHP classes that prints the traced message when you run it.

since Haxe 4.0.0

The generated PHP code is compatible with PHP 7.0.0 or later. Prior to Haxe 4, the minimum required version was PHP 5.1.0.