Home >php教程 >php手册 >__construct 构造函数用法

__construct 构造函数用法

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-13 09:53:321171browse

__construct 构造函数 类在被实例化时就会执行.

construct 自定义的函数或方法.

class myName{
function __construct($myName){    //连续两个下划线
  echo ("我的名字是:$myName
");
}
}
$name1 = new myName("小猫");
$name2 = new myName("小狗");
$name3 = new myName("小马");
?>

与之比较的是:

class myName{
function construct($myName){
  echo ("我的名字是:$myName
");
}
}
$name1 = new myName("小猫");
$name2 = new myName("小狗");
$name3 = new myName("小马");
?>

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