If you remove the constructor, print 11 without removing it, then print 33. Public $name = ' 11 '; Will this sentence not be executed?
name=33; } }$a=new man();echo $a->name;?>
Reply content:
If you remove the constructor, print 11 without removing it, then print 33. Public $name = ' 11 '; Will this sentence not be executed?
name=33; } }$a=new man();echo $a->name;?>
The declaration or initialization of a variable should be executed first, and the constructor will be assigned a value.
Isn't this the most basic grammar?
Constructors First Run
Initialize the variables first,
The constructor is then executed.
The value of $name when initialized is changed in the constructor
class man{ public $name='11'; public function __construct(){ echo $this->name; $this->name=33; }}$a=new man();echo $a->name;
?>
Results: 1133
1, when you new Man (), the construction method is executed, so the value of the $this->name property inside will be changed
The man class has a constructor that executes every time new object is executed, and the value of $name becomes 33 after execution.