|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2005-02-12 00:49 UTC] alberto dot delatorre at gmail dot com
[2005-02-12 16:39 UTC] alberto dot delatorre at gmail dot com
[2005-02-12 17:47 UTC] tony2001@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 02 17:00:02 2025 UTC |
Description: ------------ If you have an abstract method inside an abstract class (obvious) and you call that method inside another non-static method within the class, you get an error. If this is an abstract class, it is suposed that a non-static method defined in the class, may have been called from an instance of a child class of that class (cause this class is abstract), and this child class may not be abstract, to be instantiated. So the abstract method have must been overloaded in the non-abstract child class and the call in the non-static method must be valid. I encountered a waste solution, making a reference to $this in the marked lines, so the error is not be triggered. If we substitute the marked line with: $aux_this=&$this; $aux_this->_foo(); The error doesn't appear. Sorry for my english, if it is embarrasing. Reproduce code: --------------- <?php abstract class A { public function foo() { $this->_foo(); // THIS LINE IS MARKED ;) } private abstract function _foo(); } class B extends A { private function _foo(){ echo "foo!!"; } } $b=new B(); $b->foo(); ?> Expected result: ---------------- foo!! Actual result: -------------- Fatal error: Cannot call abstract method A::_foo() in myphp.php on line 4