Skip to content
A pure PHP library that makes user-defined functions redefinable at runtime.
Find file
New pull request
Latest commit 2bb0de5 @antecedent Wildcard optimizations

Patchwork 1.4

composer require antecedent/patchwork

A pure PHP library that lets you redefine user-defined functions at runtime. Released under the terms of the MIT license.

Functionality and Limitations

In other words, Patchwork is a partial implementation of runkit_function_redefine in userland PHP 5.4 code.

As of now, it only works with user-defined functions and methods, including static, final, and non-public ones.

Internal function redefinition functionality is currently only offered by core PHP extensions: Runkit, ext/test_helpers, and krakjoe/uopz.

It is, however, planned and being developed for Patchwork's next major release.


Patchwork requires at least either Zend's PHP 5.4.0 or HHVM 3.6.0 to run. Compatibility with lower versions of HHVM is possible, but has not been tested.


After running the following code, any existing and upcoming instances of Collection will automatically have an $axe in them.

This is done by redefining all methods of the class. The new definition ensures that an $axe is present and then relays control to the original definition.

use function Patchwork\{redefine, relay};

redefine([Collection::class, '*'], function() use ($axe)
    if (!$this->contains($axe)) {
    return relay();


The wiki contains detailed usage instructions and implementation notes.


If you come across any bugs in Patchwork, please report them here. Thank you!

Something went wrong with that request. Please try again.