Skip to content

Instantly share code, notes, and snippets.

@cmounce
Created February 5, 2016 01:35
Show Gist options
  • Save cmounce/98211acfe8d764a7d6bc to your computer and use it in GitHub Desktop.
Save cmounce/98211acfe8d764a7d6bc to your computer and use it in GitHub Desktop.
Patchwork, wildcards, and multiple functions
{
"require": {
"antecedent/patchwork": "1.4.0"
}
}
<?php
class Foo {
// This is the function that main.php calls.
public function bar() {
echo "You called the original bar()\n";
}
// The existence of this function causes Patchwork\restoreAll() to crash.
// Comment it out, and restoreAll() works as expected.
public function baz() {
echo "You called the original baz()\n";
}
}
<?php
require_once 'vendor/antecedent/patchwork/Patchwork.php';
require_once 'Foo.php';
// Prints the original message
$f = new Foo();
$f->bar();
// Prints the redefined message
Patchwork\redefine("Foo::*", function () {
$name = Patchwork\getFunction();
echo "You called the redefined $name()\n";
});
$f->bar();
// Should print the original message again, but restoreAll() crashes:
// PHP Fatal error: Call to a member function expire() on null in /blah/blah/CallRerouting.php on line 192
Patchwork\restoreAll();
$f->bar();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment