XP Compiler
Compiles future PHP to today's PHP.
Usage
After adding the compiler to your project via composer require xp-framework/compiler classes will be passed through the compiler during autoloading. Code inside files with a .class.php ending is considered already compiled; files need to renamed T.class.php => T.php in order to be picked up.
Example
The following code uses Hack, PHP 7.3, PHP 7.2, PHP 7.1 and PHP 7.0 features but runs on anything >= PHP 5.6. Builtin features from newer PHP versions are translated to work with the currently executing runtime if necessary.
<?php // In a file "HelloWorld.php"
use util\cmd\Console;
use lang\Type;
<<author('Timm Friebe')>>
class HelloWorld {
public const GREETING = 'Hello';
public static function main(array<string> $args): void {
$greet= ($to, $from) ==> self::GREETING.' '.$to.' from '.$from;
$author= Type::forName(self::class)->getAnnotation('author');
Console::writeLine($greet($args[0] ?? 'World', $author));
}
}Features supported
XP Compiler supports features such as annotations, arrow functions, property type-hints, the null-safe instance operator as well as all PHP 7 syntax additions. A complete list including examples can be found in our Wiki.
Implementation status
Some features from newer PHP versions as well as Hack language are still missing. The goal, however, is to have all features implemented - with the exception of where Hack's direction conflicts with PHP! An overview can be seen on this Wiki page.
To contribute, open issues and/or pull requests.





