I recently read a book and conducted a small test. The execution process of constructor and destructor is simple. If the same variable appears as an instance of different classes, in PHP, how can we construct and analyze the structure? After testing, the sequence should be constructed first. After the object is re-instantiated, the constructor is called again. At the same time, the previous instance is no longer in use. It will automatically analyze the constructor and then operate on it again, the object structure of the instance will be re-analyzed.
File 2-1.php
Code
1 // class one
2 class person
3 {
4 private $ name;
5 Public $ age = 15;
6 private $ conname;
7 function _ construct ($ Var = '000000 ')
8 {
9 $ this-> Weight = '70 ';
10 $ this-> conname = $ var;
11 echo "constructor called <br/> ";
12}
13 function get_name ()
14 {
15 return $ this-> name;
16}
17 function set_name ($ INAME)
18 {
19 $ this-> name = $ INAME;
20}
21 function _ destruct ()
22 {
23 echo '<br/>'. $ this-> conname;
24 echo '<br/> destructor call ';
25}
26}
27 // Class Two
28 class student {
29 private $ name = 'lil ';
30 public $ age = '30 ';
31 public $ Weight = '70 ';
32}
33
34 class extends_person extends person {
35 function Bank (){
36 echo 'person extends bank ';
37}
38}
39
40 $ e = new extends_person ();
41 $ e-> set_name ('aaa ');
42 echo $ e-> get_name (). "<br/> ";
43 echo $ e-> weight. "<br/> ";
44 echo $ e-> Bank ();
45
File 2-2.php
Require_once ('2-1. php ');
$ E = new person ('20140901 ');
Echo '<br/>'. $ e-> age;
Exit;
========================
Output result:
Constructor inherited
Aaa
70
The person extends banks constructor is inherited.
111
Destructor inheritance
15
456
Destructor inheritance