Skip to content

Instantly share code, notes, and snippets.

@EricMcWinNer
Last active July 26, 2021 01:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EricMcWinNer/07e95fa427bf743a75725c989cf1d816 to your computer and use it in GitHub Desktop.
Save EricMcWinNer/07e95fa427bf743a75725c989cf1d816 to your computer and use it in GitHub Desktop.
<?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