note 49916 added to language.oop

From: Date: Fri, 11 Feb 2005 23:10:23 +0000
Subject: note 49916 added to language.oop
Groups: php.notes 
Request: Send a blank email to php-notes+get-84876@lists.php.net to get a copy of this message
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(); ?> ---- Manual Page -- http://www.php.net/manual/en/language.oop.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+49916 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+49916&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+49916&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+49916&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+49916&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+49916&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+49916&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#84876) next »