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

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

WBOY
Release: 2016-06-13 13:06:21
Original
1666 people have browsed it

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() 是两个下划线
Related labels:
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