Home  >  Article  >  Backend Development  >  __construct Constructor usage_PHP tutorial

__construct Constructor usage_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:52:231616browse

__construct The constructor function will be executed when the class is instantiated.

construct a custom function or method.

class myName{
function __construct($myName){ //Two consecutive underscores
echo ("My name is: $myName
");
}
}
$name1 = new myName("Kitten");
$name2 = new myName("Puppy");
$name3 = new myName("小马");
?>

Compare this to:

class myName{
function construct($myName){
echo ("My name is: $myName
");
}
}
$name1 = new myName("Kitten");
$name2 = new myName("Puppy");
$name3 = new myName("小马");
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632487.htmlTechArticle__construct The constructor class will be executed when it is instantiated. construct A custom function or method. ?php class myName{ function __con str uct($myName){ //Two consecutive underscores echo (I...
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