Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

A pure PHP library that lets you redefine user-defined functions at runtime.

branch: master


Version 1.2.7

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


Patchwork requires PHP 5.3.0 or higher to run. It should also be noted that opcode caches might cause Patchwork to behave incorrectly due to possible interference with its preprocessing mechanism.


Patchwork loosely replicates the functionality of runkit_function_redefine in plain PHP code, with no dependencies on non-standard PHP extensions.

However, that also makes this library incapable of redefining internal PHP functions, which is possible with Runkit or ext/test_helpers.


All these steps occur at the same runtime:

(Note, however, that this example actually requires at least two separate files to run, one of them being a dummy entry script that just includes Patchwork.php and the other file, which, in turn, actually contains the example. Please see Setup for details.)

1. Define a function

function size($x)
    return count($x);

size(array(1, 2)); # => 2

2. Replace its definition

Patchwork\replace("size", function($x)
    return "huge";

size(array(1, 2)); # => "huge"

3. Undo the redefinition


size(array(1, 2)); # => 2

Further Reading

For more information, please refer to the online documentation, which can be accessed and navigated using the top menu of Patchwork's website.


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

Something went wrong with that request. Please try again.