Home >php教程 >php手册 >PHP5面向对象的一些问题反映

PHP5面向对象的一些问题反映

WBOY
WBOYOriginal
2016-06-13 11:05:271271browse

大家也许对好了,先将代码贴出来

<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面向对象里类初始化的顺序。


Statement:
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