PHPackages                             pre/phpx - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. pre/phpx

ActivePre-compiler[Utility &amp; Helpers](/categories/utility)

pre/phpx
========

0.5.0(4y ago)702503[1 issues](https://github.com/preprocess/pre-phpx/issues)1MITPHPCI failing

Since Aug 16Pushed 4y ago3 watchersCompare

[ Source](https://github.com/preprocess/pre-phpx)[ Packagist](https://packagist.org/packages/pre/phpx)[ RSS](/packages/pre-phpx/feed)WikiDiscussions main Synced 4w ago

READMEChangelog (8)Dependencies (2)Versions (9)Used By (1)

Phpx
====

[](#phpx)

Documentation can be found at [preprocess.io](https://preprocess.io#phpx).

Motivation
----------

[](#motivation)

I wanted to write a custom compiler, and this syntax appeals to me. It's not a replacement for Javascript, or even a very good implementation. But, I like it. That's all that counts.

If you want to write component-based code, without writing Javascript; then this might work for you.

Getting started
---------------

[](#getting-started)

- Clone the repository
- Install the Compoer dependencies
- Run the tests *or* execute the example scripts

This should work on PHP 7.2 (where it was developed and tested). Make an issue if it's not working on 7.2 *or* if you'd like to see things added.

What does it render?
--------------------

[](#what-does-it-render)

The goal was to decouple the compiler from the renderers. Once the Pre\\Phpx\\Html renderer moves out, you'll need to import it into your project or create a custom `render` function. The Pre\\Phpx\\Html `render` function looks like this:

```
public function render($name, $props = null)
{
    $props = $this->propsFrom($props);

    if ($function = globalFunctionMatching($name)) {
        return call_user_func($function, $props);
    }

    if ($class = globalClassMatching($name)) {
        return (new $class($props))->render();
    }

    // render HTML from a list of allowed elements...

    return $this->format("...");
}
```

This means you can define your own namespaced functions and classes, and use them in the Pre\\Phpx\\Html `render` function, like:

```
namespace Example\Application;

// don't forget to define or import render
// everywhere you use HTML-in-PHP syntax
use function Pre\Phpx\Html\render;

function MyForm($props) {
    return (

            {$props->showLabel ? Email : null}

    );
}

// ...later

print render();
```

If you'd prefer to have your components automatically prefixed, define your own `render` function, You can extend the Pre\\Phpx\\Html `render` function:

```
namespace Example\Application;

use function Pre\Phpx\classMatching;
use function Pre\Phpx\functionMatching;
use function Pre\Phpx\Html\render as renderHtml;
use function Pre\Phpx\Html\propsFrom;

define("NAMESPACES", [
    // remove this if you only have
    // namespaced classes and functions
    "global",

    // classes and functions will
    // be loaded from this namespace
    "Example\\Application",
]);

function render($name, $props = null)
{
    $props = propsFrom($props);

    if ($function = functionMatching(NAMESPACES, $name)) {
        return call_user_func($function, $props);
    }

    if ($class = classMatching(NAMESPACES, $name)) {
        return (new $class($props))->render();
    }

    return renderHtml($name, $props);
}

// ...later

print render();
```

You can define components as functions or classes:

```
function MyForm($props) {
    // render things...
}

// ...or

class MyForm
{
    public function __construct($props)
    {
        // ...store and manipulate the props
    }

    public function render()
    {
        // render things...
    }
}
```

Since you can define a custom render function, you can decide what your components are allowed to return. HTML-in-PHP syntax is converted to the following form:

```
use function Pre\Phpx\Html\Example\render;

function MyForm($props) {
    return (

            {$props->showLabel ? Email : null}

    );
}

// ...becomes

use function Pre\Phpx\Html\Example\render;

function MyForm($props)
{
    return render("form", [
        "children" => [
            $props->showLabel ?
                render("label", [
                    "htmlFor" => "email",
                    "children" => "Email",
                ]) :
                null,
            render("input", [
                "type" => "text",
                "name" => "email",
                "id" => "email",
            ]),
        ],
    ]);
}
```

You decide what your components return and what your `render` function does. The Pre\\Phpx\\Html `render` function outputs strings of HTML, and expects components rendered by it to return strings (so that they can be concatenated in an array of children).

> Returning `null` will also work.

Roadmap
-------

[](#roadmap)

- Support HTML tag warnings and rewriting
- Move HTML renderer to its own library
- Set up StyleCI and Travis
- Write more tests
- Experiment with other renderers
- Document like it's 1999

###  Health Score

32

—

LowBetter than 69% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity25

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity58

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 ~204 days

Recently: every ~257 days

Total

8

Last Release

1811d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/00089084814b5b79cd35b9f501bcc48d74c5afb2cb4703562a82e081f31c843c?d=identicon)[assertchris](/maintainers/assertchris)

---

Top Contributors

[![assertchris](https://avatars.githubusercontent.com/u/200609?v=4)](https://github.com/assertchris "assertchris (48 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/pre-phpx/health.svg)

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

PHPackages © 2026

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