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