__construct 构造函数用法_PHP教程

WBOY
Release: 2016-07-13 10:52:23
Original
1592 people have browsed it

__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("小马");
?>

www.bkjia.com true http://www.bkjia.com/PHPjc/632487.html TechArticle __construct 构造函数 类在被实例化时就会执行. construct 自定义的函数或方法. ?php class myName{ function __con str uct($myName){ //连续两个下划线 echo (我...
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!