$ This-& gt; construct ($ x); meaning class aaa {
Var $ B;
Function _ construct ($ x ){
$ This-> B = $ x;
}
Function B ($ x ){
$ This->__ construct ($ x );
}
Function c {...}
Function d (){...}
}
$ K = new aaa (x );
$ Html_text = $ k-> d ();
In the above class
Function B ($ x ){
$ This->__ construct ($ x );
}
Why can I omit it? Who can explain it in detail?
Reply to discussion (solution)
_ Construct is a constructor.
The new classname is automatically executed. The main function is to initialize the instance as you do.
If you have nothing to do, you can omit it.
Function B ($ x ){
$ This->__ construct ($ x );
}
Change
Function B ($ x ){
$ This-> B = $ x;
}
You will understand.
_ Construct constructor
It is automatically called when the class is instantiated. it is usually used for initialization.
Correct it
The original code of function B ($ x) {$ this->__ construct ($ x);} in the class is as follows:
Function aaa ($ x) {$ this->__ construct ($ x);} // correct the same name of the function and class aaa. // this sentence is not quite understandable,
In my understanding
When $ k = new aaa ("x") is used; during instantiation, function _ construct ($ x) {$ this-> B = $ x;} is executed ;} to complete the assignment;
However, other functions c {...} and function d () {...} in the class will not be executed,
The problem is:
The only function aaa with the same name as the class has only one $ this->__ construct ($ x) in the class. what does it do?
If $ k = new aaa ("x") at this time, will the instantiation be executed?
I tried it and it seems that it was not executed, because I added echo "x" to it and changed it to function aaa ($ x) {$ this->__ construct ($ x ); echo "aaaaa"; echo $ x ;}
$ K = new aaa ("x"); no output is available after instantiation. You still need to use $ k-> aaa (55555) for output after instantiation.
So I don't understand the vunction of $ this->__ construct ("the same parameter during instantiation") and what special functions does it play?