interface inheritance

From: Date: Mon, 28 Jan 2008 02:46:03 +0000
Subject: interface inheritance
Groups: php.general 
Request: Send a blank email to php-general+get-268182@lists.php.net to get a copy of this message
all, previously, on this list and elsewhere, i have raised the topic of interface inheritance, lamenting that php is void of the feature. to my utter amazement i discovered that php does in fact support interface inheritance, reading through some of Marcus Boergers' code in SPL.. i noticed RecursiveIterator extends Iterator, which is an internal interface (part of the zend engine), so i thought to myself, perhaps only internal interfaces can be extended, but then a quick test proved my suspicions wrong. in fact, interfaces can even extend multiple parent interfaces, just like java (*ducks*). here is the sample code so you can see for yourself: <?php interface Somethingable { public function doSomething(); } interface Crazyfiable { public function getCrazy(); } interface Extendable extends Somethingable, Crazyfiable { public function extend(); } class SuperClass implements Extendable { public function doSomething() { echo 'i did something ..' . PHP_EOL; } public function extend() { echo 'i extended something..' . PHP_EOL; } public function getCrazy() { echo 'im a crazy bastard now!' . PHP_EOL; } } /* * TEST HERE */ $sc = new SuperClass(); $sc->doSomething(); $sc->extend(); $sc->getCrazy(); ?> and the output: nathan@trident /usr/share/php5/splExperiment/tests $ php testInterfaceInheritence.php i did something .. i extended something.. im a crazy bastard now! i for one am quite excited. heres to happy adventures in oop-land w/ php! -nathan

« previous php.general (#268182) next »