{"id":21056042,"url":"https://github.com/xp-framework/compiler","last_synced_at":"2025-09-02T10:36:08.234Z","repository":{"id":25775334,"uuid":"106458763","full_name":"xp-framework/compiler","owner":"xp-framework","description":"Compiles future PHP to today's PHP.","archived":false,"fork":false,"pushed_at":"2025-06-10T13:00:39.000Z","size":1551,"stargazers_count":19,"open_issues_count":10,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-10T14:20:08.455Z","etag":null,"topics":["annotations","arrow-functions","ast","compiler","enums","future","hack-language","language","metaprogramming","newer-php-versions","php","php7","php8","php8-features","transpiler","xp-framework"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xp-framework.png","metadata":{"files":{"readme":"README.md","changelog":"ChangeLog.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2017-10-10T18:56:58.000Z","updated_at":"2025-05-28T19:38:57.000Z","dependencies_parsed_at":"2024-03-28T21:49:56.281Z","dependency_job_id":"651c6f14-c722-4575-a1f3-91cfddf5114d","html_url":"https://github.com/xp-framework/compiler","commit_stats":null,"previous_names":[],"tags_count":122,"template":false,"template_full_name":null,"purl":"pkg:github/xp-framework/compiler","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xp-framework%2Fcompiler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xp-framework%2Fcompiler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xp-framework%2Fcompiler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xp-framework%2Fcompiler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xp-framework","download_url":"https://codeload.github.com/xp-framework/compiler/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xp-framework%2Fcompiler/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260797728,"owners_count":23064848,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["annotations","arrow-functions","ast","compiler","enums","future","hack-language","language","metaprogramming","newer-php-versions","php","php7","php8","php8-features","transpiler","xp-framework"],"created_at":"2024-11-19T16:48:28.759Z","updated_at":"2025-09-02T10:36:08.215Z","avatar_url":"https://github.com/xp-framework.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"XP Compiler\n===========\n\n[![Build status on GitHub](https://github.com/xp-framework/compiler/workflows/Tests/badge.svg)](https://github.com/xp-framework/compiler/actions)\n[![XP Framework Module](https://raw.githubusercontent.com/xp-framework/web/master/static/xp-framework-badge.png)](https://github.com/xp-framework/core)\n[![BSD Licence](https://raw.githubusercontent.com/xp-framework/web/master/static/licence-bsd.png)](https://github.com/xp-framework/core/blob/master/LICENCE.md)\n[![Requires PHP 7.4+](https://raw.githubusercontent.com/xp-framework/web/master/static/php-7_4plus.svg)](http://php.net/)\n[![Supports PHP 8.0+](https://raw.githubusercontent.com/xp-framework/web/master/static/php-8_0plus.svg)](http://php.net/)\n[![Latest Stable Version](https://poser.pugx.org/xp-framework/compiler/version.svg)](https://packagist.org/packages/xp-framework/compiler)\n\nCompiles future PHP to today's PHP.\n\nUsage\n-----\nAfter adding the compiler to your project via `composer require xp-framework/compiler`, it will hook into the class loading chain and compile `.php`-files on-demand. This keeps the efficient code-save-reload/rerun development process typical for PHP.\n\nExample\n-------\nThe following code uses Hack language, PHP 8.4, PHP 8.3, PHP 8.2, 8.1 and 8.0 features but runs on anything \u003e= PHP 7.4. Builtin features from newer PHP versions are translated to work with the currently executing runtime if necessary.\n\n```php\n\u003c?php // In a file \"HelloWorld.php\"\n\nuse lang\\Reflection;\nuse util\\Date;\nuse util\\cmd\\Console;\n\n#[Author('Timm Friebe')]\n#[Permissions(0o777)]\nclass HelloWorld {\n  private const string GREETING= 'Hello';\n\n  public static function main(array\u003cstring\u003e $args): void {\n    $greet= fn($to, $from) =\u003e self::GREETING.' '.$to.' from '.$from;\n    $author= Reflection::type(self::class)-\u003eannotation(Author::class)-\u003eargument(0);\n\n    Console::writeLine(new Date()-\u003etoString(), ': ', $greet($args[0] ?? 'World', from: $author));\n  }\n}\n```\n\nTo run this code, use `xp -m /path/to/xp/reflection HelloWorld` in a terminal window.\n\nCompilation\n-----------\nCompilation can also be performed explicitely by invoking the compiler:\n\n```bash\n# Compile code and write result to a class file\n$ xp compile HelloWorld.php HelloWorld.class.php\n\n# Compile standard input and write to standard output.\n$ echo \"\u003c?php ...\" | xp compile -\n\n# Compile src/main/php and src/test/php to the dist folder.\n$ xp compile -o dist src/main/php/ src/test/php/\n\n# Compile src/main/php to the dist.xar archive\n$ xp compile -o dist.xar src/main/php/\n\n# Compile src/main/php, do not write output\n$ xp compile -n src/main/php/\n\n# Target PHP 7.4 (default target is current PHP version)\n$ xp compile -t php:7.4 HelloWorld.php HelloWorld.class.php\n\n# Emit XP meta information (includes lang.ast.emit.php.XpMeta):\n$ xp compile -t php:7.4 -a php:xp-meta -o dist src/main/php\n```\n\nThe -o and -n options accept multiple input sources following them.\nThe -q option suppresses all diagnostic output except for errors.\n\nFeatures supported\n------------------\n\nXP Compiler supports features such as annotations, arrow functions, enums, property type-hints, the null-safe instance operator as well as all PHP 7 and PHP 8 syntax additions. A complete list including examples can be found [in our Wiki](https://github.com/xp-framework/compiler/wiki).\n\n### More features\n\nAdditional syntax like an `is` operator, generics or record types can be added by installing compiler plugins from [here](https://github.com/xp-lang):\n\n```bash\n$ composer require xp-lang/php-is-operator\n# ...\n\n$ xp compile\nUsage: xp compile \u003cin\u003e [\u003cout\u003e]\n\n@FileSystemCL\u003c./vendor/xp-framework/compiler/src/main/php\u003e\nlang.ast.emit.PHP74\nlang.ast.emit.PHP80\nlang.ast.emit.PHP81\nlang.ast.emit.PHP82\nlang.ast.emit.PHP83 [*]\nlang.ast.emit.PHP84\nlang.ast.emit.PHP85\nlang.ast.syntax.php.Using [*]\n\n@FileSystemCL\u003c./vendor/xp-lang/php-is-operator/src/main/php\u003e\nlang.ast.syntax.php.IsOperator\n```\n\nImplementation status\n---------------------\n\nSome 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](https://github.com/xp-framework/compiler/wiki/Implementation-status).\n\nTo contribute, open issues and/or pull requests.\n\nSee also\n--------\n\n* [XP Compiler design](https://github.com/xp-framework/compiler/wiki/Compiler-design)\n* [XP RFC #0299: Make XP compiler the Babel of PHP](https://github.com/xp-framework/rfc/issues/299)\n* [XP RFC #0327: Compile-time metaprogramming](https://github.com/xp-framework/rfc/issues/327)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxp-framework%2Fcompiler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxp-framework%2Fcompiler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxp-framework%2Fcompiler/lists"}