Last active
July 26, 2021 01:52
-
-
Save EricMcWinNer/07e95fa427bf743a75725c989cf1d816 to your computer and use it in GitHub Desktop.
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 A { | |
private function foo() { | |
echo "success!\n"; | |
} | |
public function test() { | |
static::foo(); | |
} | |
} | |
class B extends A { | |
/* foo() will be copied to B, hence its scope will still be A and | |
* the call be successful */ | |
} | |
class C extends A { | |
private function foo() { | |
/* original method is replaced; the scope of the new one is C */ | |
echo "failure"; | |
} | |
} | |
$c = new C(); | |
$c->test(); // Fails because the private function's scope is in C and trying to access it from A will fail |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment