PHP でメソッドをオーバーロードできないことはわかっています。そして、私の知る限りprivate
、クラスのメソッドは、基本クラスを拡張するクラスには見えません。では、なぜこれが機能しないのでしょうか。
class Base {
private function foo($arg) {
print "Base $arg";
}
}
class Child extends Base {
public function foo() {
print "Child";
}
}
$c = new Child;
print $c->foo();
エラー:
PHP Strict Standards: Declaration of Child::foo() should be compatible with Base::foo($arg) in /var/www/boludo.php on line 17
foo($arg)
であるため、メソッドはChild
クラスで非表示であると想定しましたprivate
。だから、私は をオーバーロードしているのではなくfoo
、 というメソッドを作成しているだけですfoo
。