Now attempting to redefine the sayFoo method, imported from FooSayingTrait, will fail, albeit without producing any errors:
Patchwork\replace("Babbler::sayFoo", function() {
echo "spam";
});
Babbler::sayFoo(); # prints "foo", not "spam" as one would expect
This happens because everytime Babbler::sayFoo is called, it identifies itself with Patchwork by its original name, that is, Babbler::speak. Since there aren't yet any patches for Babbler::speak, the original implementation of this method runs. (For the actual call interception code that Patchwork makes run on every call to a user-defined function, see CALL_INTERCEPTION_CODE.)
This is supported by the fact that trying to redefine Babbler::speak will redefine Babbler::sayFoo as well:
Patchwork\replace("Babbler::speak", function() {
echo "eggs";
});
Babbler::speak(); # prints "eggs"Babbler::sayFoo(); # prints "eggs", not "foo" or "spam" as it should
The text was updated successfully, but these errors were encountered:
Let's say we have a trait with a single method:
This trait is used by a class, importing the trait's method under a different name. The original name of the imported method is taken by a new method:
Now attempting to redefine the
sayFoo
method, imported fromFooSayingTrait
, will fail, albeit without producing any errors:This happens because everytime
Babbler::sayFoo
is called, it identifies itself with Patchwork by its original name, that is,Babbler::speak
. Since there aren't yet any patches forBabbler::speak
, the original implementation of this method runs. (For the actual call interception code that Patchwork makes run on every call to a user-defined function, see CALL_INTERCEPTION_CODE.)This is supported by the fact that trying to redefine
Babbler::speak
will redefineBabbler::sayFoo
as well:The text was updated successfully, but these errors were encountered: