Re: Inheritance of class methods
| From: | Yeti | Date: | Thu, 23 Oct 2008 11:26:03 +0000 |
| Subject: | Re: Inheritance of class methods | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-282344@lists.php.net to get a copy of this message | ||
Using extends means that a class IS-A substructure of its parent class(es).
EXAMPLE:
class plant { };
class tree extends plant { };
class apple_tree extends tree { };
apple_tree inherits all methods and attributes from plant and tree
So if there was a methods plant->growth() you can also call it from
tree and apple_tree
IS-A versus HAS-A
apple_tree IS-A tree
apple_tree HAS-A fruit called apple
So apple does not extend apple_tree because it is not a tree
EXAMPLE:
class apple {
var color = 'blue';
var inhabitant = 'worm';
}
class apple_tree extends tree {
var apples = array(new apple());
}