PHPackages                             datahihi1/pipefn - 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. datahihi1/pipefn

ActiveLibrary

datahihi1/pipefn
================

Polyfill for PHP 8.5 pipe operator supporting closures, functions, and methods.

00PHPCI passing

Since Oct 28Pushed 6mo agoCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

PHP Pipe Function Polyfill
==========================

[](#php-pipe-function-polyfill)

A lightweight polyfill that provides a `pipe()` function for method chaining and functional pipelines in PHP 5.6+ applications. This function allows you to chain method calls, closures, functions, and more in a clean, readable way.

Installation
------------

[](#installation)

### Via Composer

[](#via-composer)

```
composer require datahihi1/pipefn:dev-main
```

### Manual Installation

[](#manual-installation)

1. Download the `pipefn.php` file
2. Include it in your project: ```
    require_once 'pipefn.php';
    ```

Usage
-----

[](#usage)

The `pipe()` function takes an initial value and chains it through multiple steps (functions, closures, methods, callables, etc).

### Basic Syntax

[](#basic-syntax)

```
$result = pipe($value, ...$steps);
```

### Parameters

[](#parameters)

- `$value` - The initial value to be piped through the steps
- `...$steps` - Variable number of steps, which can be:
    - String function/method names (global, static, or object methods)
    - Arrays in format `[callable, [arguments]]` or `[methodName, [arguments]]`
    - Closures/functions
    - Callable arrays (e.g. `[$object, 'method']`)

Supported Usages
----------------

[](#supported-usages)

### 1. Chain closures/functions

[](#1-chain-closuresfunctions)

```
pipe(" hi ", fn($v) => trim($v), fn($v) => strtoupper($v), fn($v) => $v . "!");
// Result: "HI!"
```

### 2. Global function names

[](#2-global-function-names)

```
pipe(" test ", 'trim', 'strtoupper');
// Result: "TEST"
```

### 3. Static method (Class::method)

[](#3-static-method-classmethod)

```
pipe("hey", 'MyClass::upper');
pipe("a", ['MyClass::append', ['b']]);
// Result: "HEY", "ab"
```

### 4. Object method (with or without arguments)

[](#4-object-method-with-or-without-arguments)

```
$user = new class('john') {
    public $name;
    public function __construct($n){$this->name = $n;}
    public function setName($n){$this->name=$n; return $this;}
    public function upper(){ $this->name = strtoupper($this->name); return $this; }
    public function get(){return $this->name;}
};
pipe($user, ['setName', ['jane']], 'upper', 'get');
// Result: "JANE"
```

### 5. Callable array (e.g. \[\[$obj, 'method'\], \[args\]\])

[](#5-callable-array-eg-obj-method-args)

```
pipe("x", [[$obj, 'method'], ['y']]);
// Calls $obj->method("x", "y")
```

### 6. Closure with multiple arguments

[](#6-closure-with-multiple-arguments)

```
pipe("a", [fn($v, $x, $y) => $v . $x . $y, ['b', 'c']]);
// Result: "abc"
```

### 7. Function with callback (e.g. array\_map)

[](#7-function-with-callback-eg-array_map)

```
pipe([1,2,3], ['array_map', [fn($x)=>$x*2]], 'array_sum');
// Result: 12
```

### 8. No steps (returns value unchanged)

[](#8-no-steps-returns-value-unchanged)

```
pipe("hello"); // Result: "hello"
```

### 9. Error handling

[](#9-error-handling)

If a step is not callable or invalid, an `InvalidArgumentException` is thrown with a clear message.

Requirements
------------

[](#requirements)

- PHP &gt;= 5.6
- No additional dependencies

Features
--------

[](#features)

- ✅ PHP 5.6+ compatibility
- ✅ Method chaining with arguments
- ✅ Closure/function/callable support
- ✅ Callable array (e.g. `[$obj, 'method']`)
- ✅ Lightweight (single file)
- ✅ No external dependencies
- ✅ Automatic function/method existence check
- ✅ Clear error messages for debugging

License
-------

[](#license)

This project is open source and available under the [MIT License](LICENSE).

Contributing
------------

[](#contributing)

Contributions are welcome! Please feel free to submit a Pull Request.

### Give it a star if you find it useful! ⭐ :v

[](#give-it-a-star-if-you-find-it-useful--v)

###  Health Score

16

—

LowBetter than 5% of packages

Maintenance46

Moderate activity, may be stable

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity13

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://www.gravatar.com/avatar/9d4e04716bebfe938a06dfd6da1d7c0c51927d8549a2dbcdbd72d23a8c8c5f79?d=identicon)[datahihi1](/maintainers/datahihi1)

---

Top Contributors

[![datahihi1](https://avatars.githubusercontent.com/u/148314027?v=4)](https://github.com/datahihi1 "datahihi1 (3 commits)")

### Embed Badge

![Health badge](/badges/datahihi1-pipefn/health.svg)

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

PHPackages © 2026

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