Can we extend from extended class in php like this: class Milk extends Sheep { // some stuff } class Sheep extends Animal { // some stuff } class Animal { // some stuff } PHP: Can we inherit this way or this is not allowed? If I cannot do this, then what are possible options?
You can absolutely extend multiple classes! Quick demo: <?php class Animal { // some stuff } class Mammal extends Animal { public function birth() { return'Live young'; } } class Primate extends Mammal { public function hasBodyHair() { return true; } } class Human extends Primate { private$name; publicfunction__construct($name) { $this->name = $name; } public function getName() { return $this->name; } public function useTools() { return true; } } $human = new Human('John Doe'); printf("Our human %s:\n", $human->getName()); printf("\t%s tools\n", $human->useTools() ? 'uses' : 'does not use'); printf("\t%s body hair\n", $human->hasBodyHair() ? 'has' : 'does not have'); printf("\tgives birth to %s", $human->birth()); PHP: Output: Our human John Doe: uses tools has body hair gives birth to Live young Code (markup):