PHPackages                             xphp-lang/xphp - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. xphp-lang/xphp

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

xphp-lang/xphp
==============

Parse xphp files and convert them into php files

v0.2.1(1mo ago)281↓88.9%[1 PRs](https://github.com/xphp-lang/xphp/pulls)3MITPHPPHP ^8.4.0CI passing

Since Jun 1Pushed 1w ago1 watchersCompare

[ Source](https://github.com/xphp-lang/xphp)[ Packagist](https://packagist.org/packages/xphp-lang/xphp)[ Docs](https://github.com/xphp-lang/xphp)[ RSS](/packages/xphp-lang-xphp/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (3)Dependencies (9)Versions (14)Used By (3)

xphp
====

[](#xphp)

What it is
----------

[](#what-it-is)

`xphp` is a superset of `php` that gives developers real generics, powered by monomorphization at compile time -- one specialized class per concrete instantiation, no runtime dispatch overhead.

In a more inspirational mood, it is a fast lane for the `php` language, a bridge between what developers need today and what `php` will support in the future.

> **Heads up**: `xphp` is heavily inspired by [PHP RFC: bound-erased generic types](https://wiki.php.net/rfc/bound_erased_generic_types), and the RFC drives the surface syntax -- turbofish `Name::` at call sites, bare `` at declarations and type-hint positions, `:` for bounds. The **intent** is that any `.xphp` source you write today stays valid against a future PHP runtime.
>
> Runtime semantics may diverge. `xphp` monomorphizes each generic instantiation into a distinct, fully-typed class -- the concrete type is baked in and visible to reflection. The RFC erases bounds at runtime instead. Both are honest design choices for different goals, and the gap may widen as the RFC evolves. `xphp` will track the syntax wherever practical and call out any divergence explicitly in the docs.

How it works
------------

[](#how-it-works)

Generics specialize into concrete classes with native typehints the engine enforces, so the safety is real and the abstraction compiles away to nothing.

The compiler turns `xphp` into regular `php`. The runtime sees ordinary classes; richer abstractions live entirely in the source you write and at build time.

Ecosystem and community first
-----------------------------

[](#ecosystem-and-community-first)

The single biggest asset of any programming language is the community and ecosystem around it, much more than its syntax and features.

We believe that meeting a community where it is, respecting their culture, history and work compounds far better than asking them to leave all of that behind.

The design choice to compile to vanilla `php` is a deliberate commitment to **contribute** to the `php` community and its ecosystem.

Principles
----------

[](#principles)

Whenever we make an architectural decision, it must be supported by the following non-negotiable principles:

### 1. Zero Runtime Penalty

[](#1-zero-runtime-penalty)

Abstractions should not cost performance. By relying on monomorphization rather than runtime reflection hacks, the output is plain `php` classes. `opcache`likes that, and execution speed remains identical to handwritten, optimized `php` code.

### 2. Maximum Runtime Safety

[](#2-maximum-runtime-safety)

`xphp` bakes the types directly into the generated `php` code. If a boundary is crossed or a third-party plain `php` library misuses your code, it triggers a native `php` error. The runtime never lies.

### 3. Progressive Enhancement

[](#3-progressive-enhancement)

It must play nicely with normal `php` codebases. A team should be able to write a single `xphp` file in a `php` application, compile it, and use it seamlessly.

No custom runtimes, no `HHVM` style ecosystem splits.

### 4. Developer Experience

[](#4-developer-experience)

The tooling must be fast and native as in every modern ecosystem. IDEs should be able to read `xphp` files, while the `php` runtime happily consumes the compiled `php` files.

Generics: the start, not the finish line
----------------------------------------

[](#generics-the-start-not-the-finish-line)

Adding native generics to `php` -- a [long-awaited php feature](https://wiki.php.net/rfc/generics) -- is genuinely [hard work](https://thephp.foundation/blog/2024/08/19/state-of-generics-and-collections/).

The object model that's served the ecosystem for two decades doesn't bend easily.

Supporting generics proves that the compile-to-vanilla model handles non-trivial type-system additions. The remaining features are on the [roadmap](docs/roadmap.md): type aliases, literal types, mapped and conditional types to name a few.

Quick start
-----------

[](#quick-start)

```
composer require --dev xphp-lang/xphp
```

Add the autoload mapping to your `composer.json` and run `composer dump-autoload`:

```
{
  "autoload": {
    "psr-4": {
      "XPHP\\Generated\\": ".xphp-cache/Generated/",
      "App\\": ["src", "dist"]
    }
  }
}
```

Write a generic class and use it:

```
// src/Collection.xphp
namespace App;

class Collection {
    private array $items = [];

    public function add(T $item): void { $this->items[] = $item; }
    public function first(): ?T { return $this->items[0] ?? null; }
}

// src/Use.xphp
namespace App;

$users = new Collection::();
$users->add(new User('Alice'));
$users->add(new User('Bob'));
echo $users->first()->name;
```

Compile:

```
vendor/bin/xphp compile src dist .xphp-cache
```

That's the whole loop: install, set up autoload, write `.xphp`, compile. `dist/` holds your rewritten code; `.xphp-cache/Generated/`holds the specialized classes. Both can be gitignored and rebuilt in CI.

See also
--------

[](#see-also)

- [Getting started](docs/getting-started.md) -- full walkthrough including PSR-4 details, runtime semantics, and what the generated PHP looks like
- [Syntax tour](docs/syntax/index.md)
- [Caveats](docs/caveats.md)
- [Type-system comparison](docs/guides/comparison.md)
- [Roadmap](docs/roadmap.md)
- [Changelog](CHANGELOG.md)

###  Health Score

45

—

FairBetter than 91% of packages

Maintenance96

Actively maintained with recent releases

Popularity15

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~8 days

Total

5

Last Release

19d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4133b1f33970c9925c7e2219f6d3e76ffa12eae30a4eacdb1b6fbd04e6be99f0?d=identicon)[math3usmartins](/maintainers/math3usmartins)

---

Top Contributors

[![math3usmartins](https://avatars.githubusercontent.com/u/585688?v=4)](https://github.com/math3usmartins "math3usmartins (299 commits)")

---

Tags

phpgenericstype-systemmonomorphizationtranspilerXPHP

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/xphp-lang-xphp/health.svg)

```
[![Health](https://phpackages.com/badges/xphp-lang-xphp/health.svg)](https://phpackages.com/packages/xphp-lang-xphp)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3345.3M347](/packages/psalm-plugin-laravel)[jolicode/castor

A lightweight and modern task runner. Automate everything. In PHP.

54643.3k4](/packages/jolicode-castor)[rector/rector-src

Instant Upgrade and Automated Refactoring of any PHP code

136406.3k14](/packages/rector-rector-src)[psx/schema

Parse and generate data schema formats

57245.5k24](/packages/psx-schema)[laraveldaily/filacheck

Static analysis for Filament projects - detect deprecated patterns and code issues

12175.6k1](/packages/laraveldaily-filacheck)[aeliot/todo-registrar

Register TODOs from source code in issue tracker

153.0k](/packages/aeliot-todo-registrar)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
