use Patchwork as p;

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

size([1, 2]); # => 2

1. Define a function

p\redefine('size', function($x)
    $u = str_repeat('u', p\relay());
    return 'h' . $u . 'ge';

size([1, 2]); # => "huuge"

2. Replace its definition


size([1, 2]); # => 2

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

3. Undo the redefinition

With redefinable methods, one no longer needs IoC to make testing possible. It is up to the developer to make good use of this freedom. The best practices of languages with natively redefinable methods (JavaScript, Ruby, Python) might serve as an useful reference.

AOP is theoretically possible with Patchwork, yet as of version 1.4, it is discouraged due to performance considerations.

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.