Could you tell me what is wrong with this program? I have created a user class, which has four private attributes: "Name", "student ID", "age", and "contact number, the constructor must assign values to the attribute "name" and assign values and access to other attributes through methods. Print the user information of "Michael", "200440132", "21", and "63886666. & Lt ;? PhpclassMessage {private $ name; could you tell me something wrong with this program?
Create a user class that has four private attributes: "Name", "student ID", "age", and "contact number". you must assign a value to the "name" attribute through the constructor, other attributes are also assigned and accessed through methods. Print the user information of "Michael", "200440132", "21", and "63886666.
Class Message
{
Private $ name;
Private $ num;
Private $ age;
Private $ tel;
Function _ construct ($ name, $ num, $ age, $ tel)
{
$ This-> name = $ name;
$ This-> num = $ num;
$ This-> age = $ age;
$ This-> tel = $ tel;
}
Function say ()
{
Echo "User:" $ this-> name"
Student ID: "$ this-> num"
Age: "$ this-> age"
Contact number: "$ this-> tel;
}
$ P = new Message ("zhang san", 20010000132,21, 63886666 );
$ P-> say ();
?>
------ Solution --------------------
PHP code
Function say () {echo "User:". $ this-> name ."
Student ID: ". $ this-> num ."
Age: ". $ this-> age ."
Contact number :". $ this-> tel; // The serial number is useless here} // the serial number is not closed, with less braces $ p = new Message ("zhang san", 20010000132,21, 63886666 );
------ Solution --------------------
Echo "User:". $ this-> name ."
Student ID: ". $ this-> num ."
Age: ". $ this-> age ."
Contact number: ". $ this-> tel;
Note connector
------ Solution --------------------
PHP code
Name = $ name; $ this-> num = $ num; $ this-> age = $ age; $ this-> tel = $ tel;} function say () {echo "User :". $ this-> name."
Student ID: ". $ this-> num ."
Age: ". $ this-> age ."
Contact number :". $ this-> tel; // variable and string connector .}} // write less.} $ p = new Message ("zhang san", 20010000132,21, 63886666); $ p-> say ();?>
------ Solution --------------------
Thank you for not ending the post for half a day.