Function is a system keyword, which means defining a method, followed by a space, and then the root method name (__construct
Is the method name). Yours has no spaces.
__construct is a built-in system called magic method, which is automatically executed every time a class is instantiated.
There is also a call to a member variable of a class without adding a $ in front of the variable, such as:
$ this-& gt; School _ name = $ name correct.
$ this-& gt; Error in $ school _ name = $ name
& lt? Server-side programming language (abbreviation of professional hypertext preprocessor)
Class school {
public $ school _ name
public $ school _ student
Public $ school _ room
Public $ school _ teacher
function __construct($name,$student,$room,$teacher) {
$ this-& gt; school _ name = $ name
$ this-& gt; school _ student = $ student
$ this-& gt; school _ room = $ room
$ this-& gt; School _ teacher = $ teacher;
}
Function display () {
Echo "! @#$%^&; *";
}
}
Class People's Development School {
public $ teachername
function __construct($tname,$studentconsts) {
$ this-& gt; Teacher name = $ tname
$ this-& gt; school _ student = $ studentconsts
}
Function display () {
Return to "Today's class". $ this-& gt; Teacher's name. Lecturer, student. $ this-& gt; School _ students. "people";
}
}
Tongji campus {
Function display () {
Return to "School Name:". $ this-& gt; Name of the school. Number of students. $ this-& gt; School _ students. Number of classrooms. $ this-& gt; School classrooms. Number of teachers. $ this-& gt; School _ teacher;
}
}
$a = Newcomer (Weekly Volume 20);
$b = new school ("DZ", 20, 50, 2);
echo $ a-& gt; Display (). “& ltbr >; ;
echo $ b-& gt; show();
& gt