Skip to content

Instantly share code, notes, and snippets.

@mhmohon
Last active March 22, 2019 13:15
Show Gist options
  • Save mhmohon/e668b3f747fd6b8b52a9778ae0020070 to your computer and use it in GitHub Desktop.
Save mhmohon/e668b3f747fd6b8b52a9778ae0020070 to your computer and use it in GitHub Desktop.
PHP inheritence
<?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