5. Object-Oriented Programming
Activity 5.1: Building a Student and Professor Object Relationship
Solution
The steps to complete the activity are as follows:
- Create a directory named
activity1to put all our activity content in it. This should be our working directory (you cancdto the directory). - Create a directory named
Studentinside theactivity1directory to put the namespacedStudentclass in it. - Create a PHP file called
Student.phpinside theStudentdirectory. - Declare a
Studentclass where theStudentclass has been namespaced asStudentand has two member attributes,$nameand$title, which arestudentby default. The constructor method accepts the student's name as an argument. The argument is hinted with its desired type asstring(anything other thanstringwill produce an error) and assigns it to the$nameproperty using$this->name. So, whenever we instantiate theStudentclass, we should call the class by its namespace, such as the...