Please solve the following PHP OOP class implementation.
The Base Class: Create a new file called animal.php in your lab 5 folder. In this file instantiate a namespace called Animal, followed by a new class called Animal. The Animal class shall have the following properties: protected $name; protected $legs; protected $type; protected $food; protected $environment; Set, Get, Construct, and a Create() function. For the Construct method, initialize all of the protected variables and for the build function output all of the variables with the name and value for each. Here, the Animal class will be your base class. The Traits: Next create two traits: 1. The Talk trait, which has a function sing($sound) that simply echoes out “This $type talks with a $song.”. 2. The Walk trait, which has a function move() that echoes out “This $type walks and runs on $legs legs”; The Cat Class: Create a Cat class that inherits from the Animal base class. Use the traits Stereo and Engine in this class. The Cat class has the following properties: protected $color; protected $fur; protected $age;
Override the functions in the Animal base class, and also override the trait functions move() and sing($song) to say something different like: “Singing $song with my Cat” for sing($song) and “Walking on all $legs with my Cat!”. Finally, override the Create() function to print out the Animal properties and the Cat’s properties
Please solve the following PHP OOP class implementation. The Base Class: Create a new file called animal.php in your lab
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am