note 94288 added to language.oop5.inheritance

From: Date: Tue, 27 Oct 2009 14:01:45 +0000
Subject: note 94288 added to language.oop5.inheritance
Groups: php.notes 
Request: Send a blank email to php-notes+get-162148@lists.php.net to get a copy of this message
You can force a class to be strictly an inheritable class by using the "abstract" keyword. When you define a class with abstract, any attempt to instantiate a separate instance of it will result in a fatal error. This is useful for situations like a base class where it would be inherited by multiple child classes yet you want to restrict the ability to instantiate it by itself. Example........ <?php abstract class Cheese { //can ONLY be inherited by another class } class Cheddar extends Cheese { } $dinner = new Cheese; //fatal error $lunch = new Cheddar; //works! ?> ---- Server IP: 192.41.40.227 Probable Submitter: 216.201.124.166 ---- Manual Page -- http://www.php.net/manual/en/language.oop5.inheritance.php Edit -- https://master.php.net/note/edit/94288 Del: integrated -- https://master.php.net/note/delete/94288/integrated Del: useless -- https://master.php.net/note/delete/94288/useless Del: bad code -- https://master.php.net/note/delete/94288/bad+code Del: spam -- https://master.php.net/note/delete/94288/spam Del: non-english -- https://master.php.net/note/delete/94288/non-english Del: in docs -- https://master.php.net/note/delete/94288/in+docs Del: other reasons-- https://master.php.net/note/delete/94288 Reject -- https://master.php.net/note/reject/94288 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#162148) next »