PHPackages                             bugadani/recursor - 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. bugadani/recursor

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

bugadani/recursor
=================

A simple library to enable quasi-recursive execution

v1.1(10y ago)030MITPHPPHP &gt;=5.5

Since Feb 7Pushed 10y ago1 watchersCompare

[ Source](https://github.com/bugadani/Recursor)[ Packagist](https://packagist.org/packages/bugadani/recursor)[ RSS](/packages/bugadani-recursor/feed)WikiDiscussions master Synced 2w ago

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

Recursor
========

[](#recursor)

Recursor enabled execution of recursive algorithms in an iterative manner by utiliting PHP's generator feature. This is particularly useful, because there may be algorithms that are easy to implement recursively but hard iteratively. Also, PHP imposes an artificial nesting limit on recursion.

To transform a recursive function into a quasi-recursive one using Recursor, basically the only work that is needed is to replace `return` keywords with `yield` and recusrive function calls should also be prefixed with `yield`.

An example that will generate the nth Fibonacci-number:

```
$fibonacci = function ($x) use (&$fibonacci) {
    if ($x === 0) {
        yield 0;
    } else if ($x === 1) {
        yield 1;
    } else {
        $x1 = (yield $fibonacci($x - 1));   //retrieves return value of recursive call
        $x2 = (yield $fibonacci($x - 2));
        yield $x1 + $x2;                    //yielding a non-generator acts as a return
    }
};

$wrapped = new Recursor($fibonacci);

$wrapped(5); // returns 5
$wrapped(6); // returns 8

```

Notes
-----

[](#notes)

- Recursor is built for PHP 5.5. This means that PHP7's generator-return is not supported. As a workaround, functions will "return" the first non-generator value it yields and because of this, they will not be able to generate sequences.
- If you wish to yield a generator that should not be executed, you can wrap it in `\IteratorIterator` or a custom wrapper.

Downsides
---------

[](#downsides)

Recursor relies heavily on generators. Each recursive call instantiates and executes a generator, which has a certain CPU and memory overhead. Also, the actual executor function is quite complicated which imposes even more overhead. Because of this, relying on Recurson in performance-sensitive applications is not recommended and an iterative solution should be implemented.

###  Health Score

26

—

LowBetter than 40% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity61

Established project with proven stability

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

Total

4

Last Release

3749d ago

Major Versions

v1.1 → v2.0-beta2016-05-02

PHP version history (2 changes)v1.0PHP &gt;=5.5

v2.0-betaPHP &gt;=7.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/2ba12833634c15d1916a7f3f29be4d1a89d40c36e7ebab46a576ff9b6e75caa6?d=identicon)[bugadani](/maintainers/bugadani)

---

Top Contributors

[![bugadani](https://avatars.githubusercontent.com/u/977627?v=4)](https://github.com/bugadani "bugadani (8 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/bugadani-recursor/health.svg)

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

###  Alternatives

[brumann/polyfill-unserialize

Backports unserialize options introduced in PHP 7.0 to older PHP versions.

333.8M1](/packages/brumann-polyfill-unserialize)[nxp/russian-porter-stemmer

Russian porter stemmer

4592.1k1](/packages/nxp-russian-porter-stemmer)[cheprasov/php-parallel

The class allows you to run multiple operations parallel in different processes and send results to the main process. Useful if you need to run multiple independent operations simultaneously, instead of sequential execution, or if you run several independent queries, for example, queries to different data bases

1712.6k5](/packages/cheprasov-php-parallel)

PHPackages © 2026

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