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

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

1. Define a function

use Patchwork as p;

p\replace("size", function($x)
{
    return "huge";
});

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

2. Replace its definition

p\undoAll();

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

# Note that all of these steps
# occur at the same runtime!

3. Undo the redefinition

Keep in mind that using Patchwork will exacerbate the temptation of writing unmaintainable code: it lowers the hurdle of testability, which also happens to be a potent extrinsic motivator to keep code maintainable.

As of now, production usage of Patchwork is strongly discouraged, unless it is absolutely necessary to do so, and the user is highly familiar with its inner workings.

Further Reading

Patchwork's documentation can be navigated using the top menu. If you have a question about Patchwork that the documentation doesn't answer, please don't hesitate to leave a comment on the documentation pages.

Reporting Issues

If you encounter any Patchwork-related problems on which the documentation is of no help, please review the currently open issues on Patchwork's GitHub site, and if you find none that would explain your problem, please open a new one.