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.)
function size($x)
{
return count($x);
}
size(array(1, 2)); # => 2
Patchwork\replace("size", function($x)
{
return "huge";
});
size(array(1, 2)); # => "huge"
Patchwork\undoAll();
size(array(1, 2)); # => 2
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!