note 33321 modified in keyword.extends by betz
| From: | betz@php.net | Date: | Mon, 23 Jun 2003 08:15:56 +0000 |
| Subject: | note 33321 modified in keyword.extends by betz | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-50841@lists.php.net to get a copy of this message | ||
Just a quick note to make things more clear : while multiple inheritance is not allowed, several
levels of single inheritance ARE ALLOWED indeed. Just test this example :
<?
class A {
var $name='A';
function disp() {
echo $this->name;
}
}
class B extends A {
var $name='B';
}
class C extends B {
var $name='C';
}
$truc = new C() ;
$truc->disp(); // Will output C
?>
This is especially important to keep in mind while building a huge object hierarchy. for example :
+GenericObject
->+ Person
->->Employee
->+Computer
->->+WorkStation
->->-> PPC
->->-> Intel
->->+Server
->->->LDAPServer
->->->IntranetWebServer
.. and so on. Multiple level hierarchy relationship are possible in a tree-like structure (each
child has one and only one parent, except for the root object).
--was--
US/UK Version:
Just a quick note to make things more clear : while multiple inheritance is not allowed, several
levels of single inheritance ARE ALLOWED indeed. Just test this example :
<?
class A {
var $name='A';
function disp() {
echo $this->name;
}
}
class B extends A {
var $name='B';
}
class C extends B {
var $name='C';
}
$truc = new C() ;
$truc->disp(); // Will output C
?>
This is especially important to keep in mind while building a huge object hierarchy. for example :
+GenericObject
->+ Person
->->Employee
->+Computer
->->+WorkStation
->->-> PPC
->->-> Intel
->->+Server
->->->LDAPServer
->->->IntranetWebServer
.. and so on. Multiple level hierarchy relationship are possible in a tree-like structure (each
child has one and only one parent, except for the root object).
-----------------------------------------------------
FR Version :
Un petit truc : L'héritage multiple n'est pas supporté par PHP, mais l'héritage
simple sur plusieurs niveaux est PARFAITEMENT POSSIBLE. Regardez pour l'exemple le code suivant
:
<?
class A {
var $name='A';
function disp() {
echo $this->name;
}
}
class B extends A {
var $name='B';
}
class C extends B {
var $name='C';
}
$truc = new C() ;
$truc->disp(); // Affichera C
?>
C'est particulièrement important quand on souhaite construire une importante hiérarchie
d'objets, comme par exemple :
+ObjetGenerique
->+ Personne
->->Employe
->+Ordinateur
->->+StationDeTravail
->->-> PPC
->->-> Intel
->->+Serveur
->->->ServeurLDAP
->->->ServerWebIntranet
.. et ainsi de suite. la hiérarchie sur plusieurs niveaux est tout à fait possible, comme dans une
arborescence (un et un seul parent pour chaque enfant sauf l'élément racine).
http://www.php.net/manual/en/keyword.extends.php