时间:2021-07-01 10:21:17 帮助过:44人阅读
phpclass A{ public $attribute = "default value"; function operation() { echo "Something
"; echo "The value of attribute is ".$this->attribute."
"; } }class B extends A{ public $attribute = "different value"; function operation() { echo "Something else
"; echo "The value of \$attribute is ".$this->attribute."
"; } }$a = new A();$a->operation();?>
php
中间为什么要留一空格呢?
首先,你PHP的开始标签写错了,多了个空格。
其次,如果你要看方法重写的效果,你应该调用子类B,而不是父类A。