note 56072 added to language.oop5.abstract
| From: | Richard at osu1 dot php dot net | Date: | Mon, 22 Aug 2005 19:13:54 +0000 |
| Subject: | note 56072 added to language.oop5.abstract | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-94039@lists.php.net to get a copy of this message | ||
Unfortunately, abstract methods do not provide true polymorphism because they can not be used from
the context of the base class.
For example:
class base
{
abstract function public abs_fn();
function base_function()
{
$this->abs_fn(); // ### This line will fail ###
}
}
class super
{
public function abs_fn()
{
// Do something useful
}
}
$myobj = new super();
$myobj->base_function();
This fails - it complains that fn() can not be called from the base class because it is abstract.
This suggests that the base class is not actually aware that it has been instantiated by virtue of
the superclass instance. This makes abstract functions pretty useless short of defining what the
superclass must define; very similar to an interface.
This also fails if the abstract function is static, but I can sort-of understand this because there
is no context when calling base::fn() - ie - there is no way of knowing that we are referring to an
instantiated object with an implementation of fn().
----
Manual Page -- http://www.php.net/manual/en/language.oop5.abstract.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+56072
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+56072&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+56072&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+56072&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+56072&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+56072&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+56072&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+56072&report=yes
Search -- http://master.php.net/manage/user-notes.php