Skip to content

Instantly share code, notes, and snippets.

@bwg
Created March 18, 2014 15:33
Show Gist options
  • Save bwg/9622479 to your computer and use it in GitHub Desktop.
Save bwg/9622479 to your computer and use it in GitHub Desktop.
how does Bar call test() on Foo if its defined as protected?
<?php
abstract class Base {
protected static function test() {
echo get_called_class()."\n";
}
}
class Foo extends Base {
protected static function test2(){
echo get_called_class()."\n";
}
}
class Bar extends Base {
public static function fooTest() {
echo Foo::test()."\n";
}
public static function fooTest2() {
echo Foo::test2()."\n";
}
}
Bar::fooTest(); // Foo
Bar::fooTest2(); // Fatal call to protected method Foo::test2() from context 'Bar'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment