background preloader

PHP

Facebook Twitter

FAQ fr.comp.lang.php PHP. Interfaces. I was wondering if implementing interfaces will take into account inheritance. That is, can inherited methods be used to follow an interface's structure? <? Php interface Auxiliary_Platform { public function Weapon(); public function Health(); public function Shields(); } class T806 extends T805 implements Auxiliary_Platform { public function Weapon() { var_dump(__CLASS__); } public function Shields() { var_dump(__CLASS__ . "->" . __FUNCTION__); } } $T805 = new T805();$T805->Weapon();$T805->Health();$T805->Shields(); echo "<hr />"; $T806 = new T806();$T806->Weapon();$T806->Health();$T806->Shields(); ? If the code were to be the same, but instead T805 (or T806) DOES NOT implement Auxiliary_Platform, then it'll still work.

This seems to work in PHP5.2.9-2, PHP5.3 and PHP5.3.1 (my current versions). We could also do the opposite: class T805 { public function Weapon() { var_dump(__CLASS__); } } $T805 = new T805();$T805->Weapon(); Le PHP Facile - Tout pour apprendre le PHP. PHPTeam, Portail de la communauté francophone.

Tuyu

PHP Index - La passerelle française des technologies PHP: Hypertext Preprocessor.