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
activity1
to put all our activity content in it. This should be our working directory (you cancd
to the directory). - Create a directory named
Student
inside theactivity1
directory to put the namespacedStudent
class in it. - Create a PHP file called
Student.php
inside theStudent
directory. - Declare a
Student
class where theStudent
class has been namespaced asStudent
and has two member attributes,$name
and$title
, which arestudent
by default. The constructor method accepts the student's name as an argument. The argument is hinted with its desired type asstring
(anything other thanstring
will produce an error) and assigns it to the$name
property using$this->name
. So, whenever we instantiate theStudent
class, we should call the class by its namespace, such as the...