Home > Backend Development > PHP Tutorial > Reflections on some object-oriented issues in PHP5_PHP Tutorial

Reflections on some object-oriented issues in PHP5_PHP Tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-15 13:28:31
Original
830 people have browsed it

You may be interested , please post the code first

<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>
Copy after login

The result is:

b100

"a" has no output. I really don't know the order of class initialization in PHP5 object-oriented.


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/446437.htmlTechArticleMaybe everyone is right, please post the code first classa{ function__construct(){ echo "a"; } } classbextendsa{ function__construct(){ echo "b"; } private$ x = 100; publicstaticfunction...
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