PHPackages                             estrattonbailey/h - 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. [Templating &amp; Views](/categories/templating)
4. /
5. estrattonbailey/h

ActiveLibrary[Templating &amp; Views](/categories/templating)

estrattonbailey/h
=================

Functional components in PHP

v0.0.1(9y ago)116MITPHPPHP &gt;=7.0.0

Since Mar 15Pushed 8y agoCompare

[ Source](https://github.com/estrattonbailey/h)[ Packagist](https://packagist.org/packages/estrattonbailey/h)[ Docs](https://github.com/estrattonbailey/h)[ RSS](/packages/estrattonbailey-h/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependenciesVersions (2)Used By (0)

h
=

[](#h)

Functional components *a la* javascript-land, but in PHP.

Features
--------

[](#features)

1. It's "just PHP", no compiling
2. Fast [(preliminary tests)](https://gist.github.com/estrattonbailey/920042f0ff220fdabf322be84d9317fd)
3. Testable: it's just functions that return markup

Usage
-----

[](#usage)

This is a functional component library. Pass tag name, attributes, and children to the `h()` function and it will return a formatted string representing the markup you've requested.

```
require 'path/to/h.php'; // or composer (soon)

echo h('h1')([ 'style' => 'color: tomato' ])( 'Hello World' );

// generates: Hello world
```

Components
----------

[](#components)

The `h()` function returns another function unless it has been passed children, in which case it returns a string of markup. This allows you to create styled components for later reuse and composition.

```
$button = h('button')(['class'=>'button button--secondary']);

echo $button('Hello world!');

// generates: Hello world!
```

Passed attributes are merged with any previously defined attributes.

```
echo $button([
  'class'=>'button--rounded',
  'style'=>'font-style: italic'
])('Hello world!');

// generates: Hello world!
```

To add children to an existing component, either pass a single `h()` component to the returned function, or an array of children.

```
$container = h('div')(['class'=>'wrapper']);

echo $container(
  h('h1')('Hello world!')
);

// generates: Hello world!

echo $container([
  h('h1')('Heading One'),
  $button('Click me!')
]);

/* generates:

  Heading One
  Click me!

*/
```

You can also easily turn arrays of data into markup:

```
$arr = [
  'Book Title One',
  'Book Title Two'
];

echo $container(
  array_reduce($arr, function($return, $data){
    $return .= h('p')(['style'=>'block'])($data);
    return $return;
  }, '')
);

/* generates:

  Book Title One
  Book Title Two

*/
```

For more complex components, create a higher order function that returns a formatted `h()` function:

```
$table = function( $children ){
  return h('table')(['class'=>'wrapper__table'])(
    h('thead')(
      h('tr')( $children )
    )
  );
};

echo $table([
  h('td')('tabular content'),
  h('td')('tabular content'),
  h('td')('tabular content'),
  h('td')('tabular content')
]);

/* generates:

      tabular content
      tabular content
      tabular content
      tabular content

*/
```

###  Health Score

22

—

LowBetter than 21% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

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

Unknown

Total

1

Last Release

3394d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/4732330?v=4)[Eric Bailey](/maintainers/estrattonbailey)[@estrattonbailey](https://github.com/estrattonbailey)

---

Tags

componentstemplating

### Embed Badge

![Health badge](/badges/estrattonbailey-h/health.svg)

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

###  Alternatives

[twig/twig

Twig, the flexible, fast, and secure template language for PHP

8.4k457.8M6.8k](/packages/twig-twig)[mustache/mustache

A Mustache implementation in PHP.

3.3k46.6M313](/packages/mustache-mustache)[smarty/smarty

Smarty - the compiling PHP template engine

2.4k40.9M448](/packages/smarty-smarty)[symfony/ux-twig-component

Twig components for Symfony

22017.2M313](/packages/symfony-ux-twig-component)[laminas/laminas-view

Fast and type safe HTML templating library with a flexible plugin system supporting multistep template composition

7527.7M261](/packages/laminas-laminas-view)

PHPackages © 2026

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