note 95630 added to language.oop5.inheritance

From: Date: Wed, 13 Jan 2010 11:12:30 +0000
Subject: note 95630 added to language.oop5.inheritance
Groups: php.notes 
Request: Send a blank email to php-notes+get-164906@lists.php.net to get a copy of this message
In Addition to Jarrods Note, which doesn't make clear, what an abstract class is good for, I will show how to use abstract methods. <?php abstract class Cheese { /** * You can call this function in every Instance of * Cheddar and Mold (see below) */ public abstract function tastes(); } class Cheddar extends Cheese { public function tastes() { return "good"; } } class Mold extends Cheese { public function tastes() { return "bad"; } } $cheese = new Cheddar(); echo $cheese->tastes(); // echoes good $cheese = new Mold(); echo $cheese->tastes(); // echoes bad function tryCheese(Cheese $cheese) { echo $cheese->tastes(); } $cheese = new Cheddar(); tryCheese($cheese); // echoes good $cheese = new Mold(); tryCheese($cheese); // echoes bad ?> ---- Server IP: 217.160.72.57 Probable Submitter: 145.243.181.22 ---- Manual Page -- http://www.php.net/manual/en/language.oop5.inheritance.php Edit -- https://master.php.net/note/edit/95630 Del: integrated -- https://master.php.net/note/delete/95630/integrated Del: useless -- https://master.php.net/note/delete/95630/useless Del: bad code -- https://master.php.net/note/delete/95630/bad+code Del: spam -- https://master.php.net/note/delete/95630/spam Del: non-english -- https://master.php.net/note/delete/95630/non-english Del: in docs -- https://master.php.net/note/delete/95630/in+docs Del: other reasons-- https://master.php.net/note/delete/95630 Reject -- https://master.php.net/note/reject/95630 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#164906) next »