全体を書き直さずにPHPクラスを拡張しようとしています。次に例を示します。
<?
$a = new foo();
print $a->xxx();
$b = new bar();
print $b->xxx();
class foo {
const something = 10;
public function xxx() {
$this->setSomething();
return $this->something;
}
private function setSomething() {
$this->something = self::something;
}
}
class bar extends foo {
public function xxx() {
$this->setSomething();
$this->something++;
return $this->something;
}
}
?>
ただし、スクリプトを実行すると、次のエラーが発生します。
Fatal error: Call to private method foo::setSomething() from context 'bar' in test.php on line 23
bar はプライベート関数 setSomething() を継承していないようです。foo クラスを変更せずにこれを修正するにはどうすればよいですか?