Last active
March 22, 2019 13:15
-
-
Save mhmohon/e668b3f747fd6b8b52a9778ae0020070 to your computer and use it in GitHub Desktop.
PHP inheritence
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//Encapsulation with Inheritance | |
class Animal | |
{ | |
private $family; | |
private $food; | |
public function __construct($family, $food) | |
{ | |
$this->family = $family; | |
$this->food = $food; | |
} | |
public function get_family() | |
{ | |
return $this->family; | |
} | |
public function set_family($family) | |
{ | |
$this->family = $family; | |
} | |
public function get_food() | |
{ | |
return $this->food; | |
} | |
public function set_food($food) | |
{ | |
$this->food = $food; | |
} | |
} | |
class Cow extends animal{ | |
public function __construct($food, $family){ | |
parent::__construct($food, $family); | |
} | |
} | |
$cow = new Cow('grass','hibread'); | |
echo $cow->get_food(); //Result will be grass | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment