PHPackages                             srph/compose - 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. srph/compose

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

srph/compose
============

Composing function calls

v0.1.0(10y ago)013MITPHP

Since Nov 7Pushed 10y ago1 watchersCompare

[ Source](https://github.com/srph/php-compose)[ Packagist](https://packagist.org/packages/srph/compose)[ RSS](/packages/srph-compose/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (1)Versions (2)Used By (0)

compose [![Build Status](https://camo.githubusercontent.com/cc8174264dc57ebe00617255c173b0cb18080305533057d5209831f9db0b7eca/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f737270682f636f6d706f73652e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/srph/compose?branch=master) [![Latest Stable Version](https://camo.githubusercontent.com/41942466548d90c418a21c51550ffff1f2f29751102f3b4a1d3e2a2968b00769/68747470733a2f2f706f7365722e707567782e6f72672f737270682f636f6d706f73652f762f737461626c65)](https://packagist.org/packages/srph/compose) [![Total Downloads](https://camo.githubusercontent.com/1b02ff0088061d3ce589a07844a64088ac3f7b533e50b801db113502abb399b9/68747470733a2f2f706f7365722e707567782e6f72672f737270682f636f6d706f73652f646f776e6c6f616473)](https://packagist.org/packages/srph/compose) [![Latest Unstable Version](https://camo.githubusercontent.com/cb014001485042705619eab55f4764c702abdaa18636bcf4971856519dc076d0/68747470733a2f2f706f7365722e707567782e6f72672f737270682f636f6d706f73652f762f756e737461626c65)](https://packagist.org/packages/srph/compose) [![License](https://camo.githubusercontent.com/1292a8805de2c8e1316f8206ee59269b448fd507b9660ed0ed5ff747d7a0b4f6/68747470733a2f2f706f7365722e707567782e6f72672f737270682f636f6d706f73652f6c6963656e7365)](https://packagist.org/packages/srph/compose)
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

[](#compose-----)

Composing function calls in PHP

Huh?
----

[](#huh)

Here's a diff example (before and after):

```
- $h($g($f($x)))
+ compose($h, $g, $f)(x);
```

More on [Functional composition - Wikipedia](https://en.wikipedia.org/wiki/Function_composition_(computer_science)).

Installing
----------

[](#installing)

```
composer require srph/compose
```

PHP `>=5.4` is supported.

Usage
-----

[](#usage)

```
$square = function($n) {
	return $n * $n;
}

$pow = function($exponent) {
	return function($n) use ($exponent) {
		for (;$exponent--;) {
			$n .= $n;
		}

		return $n;
	}
}

$input = 2;
$f = compose($square, $pow(3), $square);
$f($input); // 4096
```

You may pass an infinite number of functions to `compose(...fn): Closure`.

###  Health Score

23

—

LowBetter than 26% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity53

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

Unknown

Total

1

Last Release

3890d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9c6418b04ec2d5f377b9de0359c587e73637a8799d8e5a496263f7f307c0db81?d=identicon)[srph](/maintainers/srph)

---

Top Contributors

[![srph](https://avatars.githubusercontent.com/u/5093058?v=4)](https://github.com/srph "srph (15 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/srph-compose/health.svg)

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

###  Alternatives

[zhuzhichao/bank-card-info

Get the bank card info

44565.3k](/packages/zhuzhichao-bank-card-info)[silverstripe/environmentcheck

Provides an API for building environment tests

35516.6k14](/packages/silverstripe-environmentcheck)

PHPackages © 2026

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