note 56072 rejected from language.oop5.abstract by betz
| From: | betz@php.net | Date: | Thu, 27 Oct 2005 14:16:34 +0000 |
| Subject: | note 56072 rejected from language.oop5.abstract by betz | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-97696@lists.php.net to get a copy of this message | ||
Note Submitter: Richard
----
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().