age = 0;
$this->weight = 100;
}
// define methods
public function eat($units) {
echo $this->name." is eating ".$units." units of food...
";
$this->weight += $units;
}
public function run() {
echo $this->name." is running...
";
}
public function kill() {
echo $this->name." is killing prey...
";
}
public function sleep() {
echo $this->name." is sleeping...
";
}
}
// extended class definition
class PolarBear extends Bear {
// constructor
public function __construct() {
parent::__construct();
$this->colour = "white";
$this->weight = 600;
}
// define methods
public function swim() {
echo $this->name." is swimming...
";
}
}
class GrizzlyBear extends Bear {
public function __construct(){
parent::__construct();
$this -> colour = "black";
$this -> weight = 684 ;
}
public function roars(){
return true;
}
}
echo "
| Naam | Wie is het | Wat kan het |
|---|---|---|
| ", $bear -> name ; for( $i=0; $i<$maxAmount; $i++){ echo " | " ; if($i < count($grizzlyKeys) ){ echo $grizzlyKeys[$i] , ": "; // null coalesce operator PHP7 https://learnxinyminutes.com/docs/php/ echo $grizzlyVars[$grizzlyKeys[$i]] ?? "Unknown. " ; } echo " | "; if($i < count($grizzlyFunctions)){ echo $grizzlyFunctions[$i]; } echo " |