note 79760 added to language.oop5.interfaces

From: Date: Tue, 11 Dec 2007 18:38:03 +0000
Subject: note 79760 added to language.oop5.interfaces
Groups: php.notes 
Request: Send a blank email to php-notes+get-133371@lists.php.net to get a copy of this message
Some interesting less-than-documented behavior. As shown below, interfaces support inheritance, and implementing multiple interfaces which inherit from the same "parent" interface will *not* cause method name clashes. Observe: <?php // Interface declarations: interface Ia { public function Foo(); } interface Ib extends Ia { public function FooBar(); } interface Ic extends Ia { public function Footurama(); } // Now let's implement them... class AB implements Ib, Ic { public function Foo() { } public function FooBar() { } public function Footurama() { } } $ab = new AB(); ?> It just becomes a matter of remembering to declare concrete methods for every interface-defined method, which could get a bit hard to read. I've already had to use this once in an app in which a User object implemented an IUser interface and extended a DB_Object class, which in turn implemented an IDB_Object interface (for decorator purposes), and both IUser and IDB_Object had a Find() method declared. Both were using the exact same Find() method, so I just put that into another interface, IFindable, and set both IUser and IDB_Object to extend IFindable. Good times. ---- Server IP: 209.41.74.194 Probable Submitter: 67.158.26.205 ---- Manual Page -- http://www.php.net/manual/en/language.oop5.interfaces.php Edit -- https://master.php.net/note/edit/79760 Del: integrated -- https://master.php.net/note/delete/79760/integrated Del: useless -- https://master.php.net/note/delete/79760/useless Del: bad code -- https://master.php.net/note/delete/79760/bad+code Del: spam -- https://master.php.net/note/delete/79760/spam Del: non-english -- https://master.php.net/note/delete/79760/non-english Del: in docs -- https://master.php.net/note/delete/79760/in+docs Del: other reasons-- https://master.php.net/note/delete/79760 Reject -- https://master.php.net/note/reject/79760 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#133371) next »