From:             alberto dot delatorre at gmail dot com
Operating system: Windows XP SP2
PHP version:      5.0.3
PHP Bug Type:     Class/Object related
Bug description:  error calling an abstract method from another method in the 
same class

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

-- 
Edit bug report at http://bugs.php.net/?id=31943&edit=1
-- 
Try a CVS snapshot (php4):   http://bugs.php.net/fix.php?id=31943&r=trysnapshot4
Try a CVS snapshot (php5.0): 
http://bugs.php.net/fix.php?id=31943&r=trysnapshot50
Try a CVS snapshot (php5.1): 
http://bugs.php.net/fix.php?id=31943&r=trysnapshot51
Fixed in CVS:                http://bugs.php.net/fix.php?id=31943&r=fixedcvs
Fixed in release:            http://bugs.php.net/fix.php?id=31943&r=alreadyfixed
Need backtrace:              http://bugs.php.net/fix.php?id=31943&r=needtrace
Need Reproduce Script:       http://bugs.php.net/fix.php?id=31943&r=needscript
Try newer version:           http://bugs.php.net/fix.php?id=31943&r=oldversion
Not developer issue:         http://bugs.php.net/fix.php?id=31943&r=support
Expected behavior:           http://bugs.php.net/fix.php?id=31943&r=notwrong
Not enough info:             
http://bugs.php.net/fix.php?id=31943&r=notenoughinfo
Submitted twice:             
http://bugs.php.net/fix.php?id=31943&r=submittedtwice
register_globals:            http://bugs.php.net/fix.php?id=31943&r=globals
PHP 3 support discontinued:  http://bugs.php.net/fix.php?id=31943&r=php3
Daylight Savings:            http://bugs.php.net/fix.php?id=31943&r=dst
IIS Stability:               http://bugs.php.net/fix.php?id=31943&r=isapi
Install GNU Sed:             http://bugs.php.net/fix.php?id=31943&r=gnused
Floating point limitations:  http://bugs.php.net/fix.php?id=31943&r=float
No Zend Extensions:          http://bugs.php.net/fix.php?id=31943&r=nozend
MySQL Configuration Error:   http://bugs.php.net/fix.php?id=31943&r=mysqlcfg

Reply via email to