$ P2 is cloned from $ p1. I want to output "I cloned from: Evan" in the _ clone () annotation. How should I write it? It seems that there is $ that, but it cannot be used. No introduction was found in Manual. The Code is as follows: {code ...} the expected result is: {generation... $ p2 is cloned from $ p1. I want to output "I cloned from: Evan" in the _ clone () annotation. How should I write it?
It seems that
$thatThis is not usable. No introduction was found in Manual.
The Code is as follows:
Name = $ name;} function _ clone () {$ this-> name = "WenryXu"; // echo "I cloned from :". name} function say () {echo "My name is :". $ this-> name."
";}}$ P1 = new Person (" Evan "); $ p1-> say (); $ p2 = clone $ p1; $ p2-> say ();
The expected result is:
My name is Evan. I cloned it from Evan. My name is WenryXu.
Thank you!
Reply content:
$ P2 is cloned from $ p1. I want to output "I cloned from: Evan" in the _ clone () annotation. How should I write it?
It seems that$thatThis is not usable. No introduction was found in Manual.
The Code is as follows:
Name = $ name;} function _ clone () {$ this-> name = "WenryXu"; // echo "I cloned from :". name} function say () {echo "My name is :". $ this-> name."
";}}$ P1 = new Person (" Evan "); $ p1-> say (); $ p2 = clone $ p1; $ p2-> say ();
The expected result is:
My name is Evan. I cloned it from Evan. My name is WenryXu.
Thank you!
The Code is as follows.
Name = $ name;} function _ clone () {echo "I cloned from :". $ this-> name. "\ n"; $ this-> name = "WenryXu";} function say () {echo "My name is :". $ this-> name. "\ n" ;}}$ p1 = new Person ("Evan"); $ p1-> say (); $ p2 = clone $ p1; $ p2-> say ();
Name = $ name;} function _ clone () {echo "I cloned from :". $ this-> name. "\ n"; $ this-> name = "WenryXu";} function say () {echo "My name is :". $ this-> name. "\ n" ;}}$ p1 = new Person ("Evan"); $ p1-> say (); $ p2 = clone $ p1; $ p2-> say ();
In this way, you can
In fact, clone is just a small copy.
During replication, all the member variables in the object are referenced only.
Therefore, the original value can be obtained through direct calls.
Output
My name is Evan.
I cloned it from Evan.
My name is WenryXu