Home > Backend Development > PHP Tutorial > __construct Constructor usage_PHP tutorial

__construct Constructor usage_PHP tutorial

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

__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...
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