Compile hack to php
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
.vscode merged Jul 18, 2018
bin merged Jul 18, 2018
example-files merged Jul 18, 2018
out merged Jul 18, 2018
src merged Jul 18, 2018
tests merged Jul 22, 2018
.gitignore fix tests Jun 9, 2018
.hhconfig init Jun 9, 2018 fix build Jun 9, 2018
.travis.yml install hhvm Jun 9, 2018
LICENSE Initial commit Jun 9, 2018 better example Jun 10, 2018
composer.json merged Jul 18, 2018
composer.lock merged Jul 18, 2018
composer.phar init Jun 9, 2018
hh_autoload.json init Jun 9, 2018
hhast-lint.json init Jun 9, 2018
phpunit.xml init Jun 9, 2018


Build Status

hack2php is a project which aims to implement a compiler to translate Hack files to PHP 5.4 files. This ability becomes useful when you have no control over the environment in which your code is supposed to run, but you still want to write your code in Hack. An example might be the development of WordPress plugins or themes.

E.g. this Hack code:

<?hh //strict

namespace codeneric\phmm\legacy\validate;
use codeneric\phmm\legacy\blub;

function blub(string $v): ?string {
    return null;

function ano(): void {
    $a = 42;
    $arr = [1, 2, 3, 42, 5, 6];
    $f = ($e) ==> {
        return \in_array($a, $arr);

is transpiled to this PHP code:

<?php //strict
namespace codeneric\phmm\legacy\validate;
use \codeneric\phmm\legacy\blub;

function blub($v){
    return null;

function ano(){
    $a = 42;
    $arr = [1, 2, 3, 42, 5, 6];
    $f = function ($e)  use($a,$arr) {
        return \in_array($a, $arr);


This project is in a very early stage, so you will probably encounter problems in some cases. If so, please create a PR and an issue as described in the Contribution section!

Getting started

Clone this repository and run hhvm composer.phar install

Compile a Hack file to PHP: ./bin/hack2php <hack-file>


There is only one test (HackToPhpTest). It reads each Hack file from the example-files directory, compiles it to PHP and checks the PHP syntax for errors. If no error were found, the test succeeds. Otherwise it fails. To add a test, simply create a new Hack file in example-files. Run the test: hhvm vendor/bin/phpunit


If you find an issue you can help to fix it. Please add a Hack file which is not compiled correctly in the example-files folder and create a PR. Or you can fix the issue directly :) But please add an example Hack file to the example-files folder nonetheless.