Home  >  Article  >  Backend Development  >  PHP 用继承 _contruct()出有关问题

PHP 用继承 _contruct()出有关问题

WBOY
WBOYOriginal
2016-06-13 10:57:051454browse

PHP 用继承 _contruct()出问题
class MyClass
{
function _contruct(){
echo 'MyClass Construct';
}
}
class ExtendClass extends MyClass
{
function _construct(){
echo 'extends clalled';
}
}
$a = new ExtendClass();
显示结果是什么都没有显示,但该成下面的代码却正常了
class MyClass
{
function MyClass(){
echo 'MyClass Construct';
}
}
class ExtendClass extends MyClass
{
function ExtendClass(){
echo 'extends clalled';
}
}
$a = new ExtendClass();
显示:extends clalled
PHP版本是5,不明白为什么会出现这种情况??

------解决方案--------------------

探讨
class MyClass
{
function _contruct(){
echo 'MyClass Construct';
}
}
class ExtendClass extends MyClass
{
function _construct(){
echo 'extends clalled';
}
}
$a = new ExtendClass();
显示结果是什么都……

------解决方案--------------------
__contruct() 是两个下划线
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