Issue
I have $name
and $age
defined in set_name()
and set_age
.
Please check index.php:
<?php
// This part needs some fixing.
class Pet {
public $name;
public $age;
// get() and set() functions for name
function set_name($name) {
$this->name = $name;
}
function get_name() {
return $this->$name;
}
// get() and set() functions for age
function set_age($age) {
$this->age = $age;
}
function get_age() {
return $this->$name;
}
}
.....
Edit:
This problem is fixed. No need for new answers!
Solution
You need constructor for your classes and don’t do the makeSound
method in your Pet class static
. Try this:
public Cat(){
makeSound(sound);
}
public Dog(){
makeSound(sound);
}
Answered By – sulox32
Answer Checked By – Pedro (BugsFixing Volunteer)