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 " Title of the document "; echo "

De beren in de Dierentuin

"; echo "
"; echo ''; echo " " ; $bear = new Bear(); $bear->name = "Yogi"; $polar_bear = new PolarBear(); $polar_bear->name = "Nanuk"; $grizzly_bear = new GrizzlyBear(); $grizzly_bear -> name = "Hercules"; foreach(Array($bear, $polar_bear, $grizzly_bear) as $bear){ $grizzlyFunctions = get_class_methods($bear); // Arg moet Class of String Zijn $grizzlyVars = get_object_vars($bear); $amountOfFunctions = count($grizzlyFunctions); $amountOfvars = count($grizzlyVars); $maxAmount = max($amountOfFunctions, $amountOfvars) ; $grizzlyKeys = array_keys($grizzlyVars); echo ""; } } echo ""; 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 "
"; ?>