note 49916 deleted from language.oop by nlopess
| From: | nlopess@php.net | Date: | Fri, 11 Feb 2005 23:19:01 +0000 |
| Subject: | note 49916 deleted from language.oop by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-84878@lists.php.net to get a copy of this message | ||
Note Submitter: alberto dot delatorre at gmail dot com
----
If you have a class hierarchy as this:
<?php
abstract class A{
//construct ommited
public function load(){
$this->_load();
}
protected abstract function _load();
}
class B extends A{
protected function _load(){
echo "loaded";
}
}
$b = new B();
$b->load();
?>
you encountered that you will have a 'calling an abstract method' in the line with
'$this->_load'. To avoid this, just make another reference to $this and then call the
method you'd want, this way:
<?php
abstract class A{
//construct ommited
public function load(){
$aux_this=&$this;
$aux_this->_load();
}
protected abstract function _load();
}
class B extends A{
protected function _load(){
echo "loaded";
}
}
$b = new B();
$b->load();
?>