Home > Backend Development > PHP Tutorial > wamp 里面OO php的初级问题

wamp 里面OO php的初级问题

WBOY
Release: 2016-06-23 13:19:18
Original
1223 people have browsed it

潜水的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();?>
Copy after login


回复讨论(解决方案)

 php 
中间为什么要留一空格呢?

首先,你PHP的开始标签写错了,多了个空格。
其次,如果你要看方法重写的效果,你应该调用子类B,而不是父类A。

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template