A pure PHP library that lets you redefine user-defined functions at runtime.
Pull request Compare This branch is 163 commits behind antecedent:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
tests
LICENSE
Patchwork.php
README.md
patchwork.phar

README.md

Patchwork

Version 1.2.4

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

Requirements

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.

Functionality

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.

Example

All these steps occur at the same runtime:

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

Patchwork\undoAll();

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.

Issues

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