note 51961 added to language.oop5.abstract
| From: | mweierophinney at gmail dot com | Date: | Sun, 17 Apr 2005 06:29:17 +0000 |
| Subject: | note 51961 added to language.oop5.abstract | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-88097@lists.php.net to get a copy of this message | ||
If you inherit from an abstract class, any method in the abstract class marked as abstract *must* be
implemented by the extending class. For example, in the following abstract class:
<?php
abstract class AbstractClass
{
public function setup() {}
abstract public function doSomething();
}
?>
the method 'doSomething' must be defined in the extending class. Thus, the following does
*not* work:
<?php
class ConcreteClass extends AbstractClass
{
public function doMyOwnThing() {}
}
?>
But the following *will*:
<?php
class ConcreteClass extends AbstractClass
{
public function doMyOwnThing() {}
public function doSomething() {}
}
?>
The lesson to learn here: if the method is truly optional to the implementation, either do not
define it in the abstract class at all, or do not tag it as abstract.
----
Manual Page -- http://www.php.net/manual/en/language.oop5.abstract.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+51961
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+51961&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+51961&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+51961&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+51961&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+51961&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+51961&report=yes
Search -- http://master.php.net/manage/user-notes.php