From:             mileskeaton at gmail dot com
Operating system: FreeBSD / any
PHP version:      5.0.3
PHP Bug Type:     Zend Engine 2 problem
Bug description:  implementing an Interface in an AbstractClass creates 
unexpected behavior

Description:
------------
A typical OOP use of the Command Pattern (design pattern) is to have an
interface, an abstract class that leaves the interface methods as
abstract, then a subclass that implements the methods (now named in both
interface and abstract class).

PHP5 wrongly complains that an interface method can not be implemented as
an abstract method in an abstract class.

As a side-effect, it seems NOT to complain when an abstract class does
*not* implement the methods named in its interface.

Reproduce code:
---------------
#1 - Abstract class not implementing interface method - WORKS but should
not!
interface MyInterface {
        function play();
}
abstract class MyAbstractClass implements MyInterface {
}

#2 - Abstract class implementing interface method as abstract - DOES NOT
WORK but should
interface MyInterface {
        function play();
}
abstract class MyAbstractClass implements MyInterface {
        abstract function play();
}

#3 - Normal OO use of interface and abstract class, but DOES NOT WORK
interface MyInterface {
        function play();
}
abstract class MyAbstractClass implements MyInterface {
        abstract function play();
}
class MyClass extends MyAbstractClass {
        function play() {
                print "Playing\n";
        }
}
$x = new MyClass;
$x->play();

Expected result:
----------------
#1 - Class (even if Abstract class) not implementing interface method
should fail.

#2 - Abstract class that implements interface method as abstract method
should not fail (expecting that actual method would come in subclass)

#3 - Normal OO use of interface and abstract class should let subclass use
of that interface/abstract method work.


Actual result:
--------------
#1 - No error

#2 - Fatal error: Can't inherit abstract function MyInterface::play()
(previously declared abstract in MyAbstractClass)

#3 - Fatal error: Can't inherit abstract function MyInterface::play()
(previously declared abstract in MyAbstractClass)


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

Reply via email to