Created
February 5, 2016 01:35
-
-
Save cmounce/98211acfe8d764a7d6bc to your computer and use it in GitHub Desktop.
Patchwork, wildcards, and multiple functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"require": { | |
"antecedent/patchwork": "1.4.0" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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"; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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