What you do is really the opposite. Inheritance is used to provide common, common functions for objects without duplicating code. Inheritance occurs from parent to child, everything that a parent can do, a child can also do, but he can do more (he extends the functionality of the parent).
class Parent { function everyoneCanDoThis() { } } class Child extends Parent {
Since this is a top-down structure, the parent should not rely on any particular Child. The Parent does not perform or does not invoke the functions of the Child. Only you call Child functions, but these functions can be inherited from the parent class.
You must put everything you want so that each object can be in the parent class. Specific functionality that relates only to a specific object passes into the Child.
Multiple inheritance is a different feature of worms that is not possible in PHP, for good reasons. Return to composition as suggested elsewhere here when you get the basics of inheritance. :)
Composition means that you take several objects and save links to them in another object. This has nothing to do with inheritance, since each of these objects may or may not inherit from the Parent class, and they are still separate objects.
class ComposedObject { private $part1 = null; private $part2 = null; public function __constructor() { $this->part1 = new Part1(); $this->part2 = new Part2(); } public function doTask() { return $this->part1->doSomeTask(); } public function doOtherTask() { return $this->part2->doSomeOtherTask(); } }
ComposedObject does not have the function itself, inherited or otherwise. But it contains two other objects, each of which has some functionality. The functionality of the βpartsβ can be displayed directly, therefore they are called as $composedObject->part1->doSomeTask() , they can be encapsulated as in the example, therefore they are called as $composedObject->doTask() and internally delegated, or you can use some __call() trickery to automatically delegate functions called by the compiled object to one of its "parts". However, this is a multiple inheritance issue; if the two "parts" contain a method with the same name as you name?