note 83766 added to language.oop5.interfaces

From: Date: Tue, 10 Jun 2008 21:29:20 +0000
Subject: note 83766 added to language.oop5.interfaces
Groups: php.notes 
Request: Send a blank email to php-notes+get-140328@lists.php.net to get a copy of this message
The structure I am working with has a lot of inheritance going on, but not all methods are specified in one place. I needed a way to make sure an interface would be used, but that the method(s) defined in the interface are defined somewhere. As such, I learned that the parent can define the interface's methods, and then the children can override that method at will without having to worry about the interface. To expand on nrg1981's example, the following is possible: <?php interface water { public function makeItWet(); } class weather { public function makeItWet() { return 'it may or may not be wet'; } public function start() { return 'Here is some weather'; } } class rain extends weather implements water { public function makeItWet() { return 'It is wet'; } } class thunder extends weather implements water { } $a = new rain(); echo $a->start() . "\n"; echo $a->makeItWet() . "\n"; $a = new thunder(); echo $a->start() . "\n"; echo $a->makeItWet() . "\n"; ?> ---- Server IP: 209.41.74.194 Probable Submitter: 63.169.105.141 ---- Manual Page -- http://www.php.net/manual/en/language.oop5.interfaces.php Edit -- https://master.php.net/note/edit/83766 Del: integrated -- https://master.php.net/note/delete/83766/integrated Del: useless -- https://master.php.net/note/delete/83766/useless Del: bad code -- https://master.php.net/note/delete/83766/bad+code Del: spam -- https://master.php.net/note/delete/83766/spam Del: non-english -- https://master.php.net/note/delete/83766/non-english Del: in docs -- https://master.php.net/note/delete/83766/in+docs Del: other reasons-- https://master.php.net/note/delete/83766 Reject -- https://master.php.net/note/reject/83766 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#140328) next »