PHPackages                             tchwork/closure-caster - 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. tchwork/closure-caster

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

tchwork/closure-caster
======================

Cast closures to single-method implementations

00PHP

Since Apr 25Pushed 3y ago1 watchersCompare

[ Source](https://github.com/tchwork/closure-caster)[ Packagist](https://packagist.org/packages/tchwork/closure-caster)[ RSS](/packages/tchwork-closure-caster/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

tchwork/closure-caster
======================

[](#tchworkclosure-caster)

This package provides a function named `closure_cast_to()` that allows turning a closure into an object implementing a single-method interface.

Imagine you have an interface like this:

```
interface TranslatorInterface
{
    public function translate(string $message, $parameters = []): string;
}
```

And that the `strtr()` function is a correct implementation for the identity translator. You can get an instance of `TranslatorInterface` delegating to `strtr()` like this:

```
$identityTranslator = closure_cast_to(strtr(...), TranslatorInterface::class);
```

This package is meant as a proof-of-concept implementation of [this RFC](https://wiki.php.net/rfc/allow_casting_closures_into_single-method_interface_implementations)which proposes to add a new `castTo` method to the native `Closure`class so that the previous example could be written like this:

```
$identityTranslator = strtr(...)->castTo(TranslatorInterface::class);
```

###  Health Score

13

—

LowBetter than 1% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity0

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity22

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/243674?v=4)[Nicolas Grekas](/maintainers/nicolas-grekas)[@nicolas-grekas](https://github.com/nicolas-grekas)

---

Top Contributors

[![nicolas-grekas](https://avatars.githubusercontent.com/u/243674?v=4)](https://github.com/nicolas-grekas "nicolas-grekas (3 commits)")

### Embed Badge

![Health badge](/badges/tchwork-closure-caster/health.svg)

```
[![Health](https://phpackages.com/badges/tchwork-closure-caster/health.svg)](https://phpackages.com/packages/tchwork-closure-caster)
```

###  Alternatives

[tareq1988/wordpress-settings-api-class

WordPress settings API Abstraction Class

46611.1k3](/packages/tareq1988-wordpress-settings-api-class)

PHPackages © 2026

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