我试图扩展
PHP类而不重写整个事情.这是一个例子:
原文链接:https://www.f2er.com/php/136023.html<? $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