大家也许对好了,先将代码贴出来
<ol class="dp-xml"> <li class="alt"><span><span>class a { </span></span></li> <li class=""><span> </span></li> <li class="alt"><span> function __construct() { </span></li> <li class=""><span> echo "a"; </span></li> <li class="alt"><span> } </span></li> <li class=""><span>} </span></li> <li class="alt"><span>class b extends a{ </span></li> <li class=""><span> function __construct(){ </span></li> <li class="alt"><span> </span></li> <li class=""><span> echo "b"; </span></li> <li class="alt"><span> } </span></li> <li class=""><span> </span></li> <li class="alt"> <span> private $</span><span class="attribute"><font color="#ff0000">x</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">100</font></span><span>; </span> </li> <li class=""><span> public static function getx(){ </span></li> <li class="alt"><span> </span></li> <li class=""> <span> return $this-</span><span class="tag"><strong><font color="#006699">></font></strong></span><span>x; </span> </li> <li class="alt"><span> } </span></li> <li class=""><span>} </span></li> <li class="alt"> <span>$</span><span class="attribute"><font color="#ff0000">x</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">new</font></span><span> b(); </span> </li> <li class=""> <span>echo $x-</span><span class="tag"><strong><font color="#006699">></font></strong></span><span>getx(); </span> </li> </ol>
结果是:
b100
“a”竟然没有输出,真不知到PHP5面向对象里类初始化的顺序。