潜水的phpers,
有个问题需要请教一下。下面这个b overriding a的程序无法展现效果。有经验的同学帮忙指导一下吧,谢谢。
<? phpclass a{ public $attribute = "default value"; function operation() { echo "something<br />"; echo "the value of attribute is ".$this->attribute."<br />"; } }class b extends a{ public $attribute = "different value"; function operation() { echo "something else<br />"; echo "the value of \$attribute is ".$this->attribute."<br />"; } }$a = new a();$a->operation();?>
php
中间为什么要留一空格呢?
首先,你PHP的开始标签写错了,多了个空格。
其次,如果你要看方法重写的效果,你应该调用子类B,而不是父类A。
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号