考虑下面的代码:为什么可以在PHP中重写实例变量而不是在Java中?
<?php
class Base {
protected $name = "Base";
public function getName() {
return $this->name;
}
}
class Foo extends Base {
protected $name = "Foo";
}
$f = new Foo();
echo $f->getName(); // output: Foo
$b = new Base();
echo $b->getName(); // output: Base
因为在其他语言如Java不会让你覆盖实例变量,但有可能在PHP。
是因为PHP是弱类型语言所以可能吗?
我没票了,所以我不能碰到你的答案,但这是唯一一个远程接近回答为什么在PHP中,超级伊娃被覆盖的问题,而在Java et al,超级伊娃被阴影/隐藏(并且它们不完全相同)。 – BoltClock 2010-10-24 18:25:31