php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #31207 implementing an Interface in an AbstractClass creates unexpected behavior
Submitted: 2004-12-20 18:19 UTC Modified: 2004-12-20 22:45 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: mileskeaton at gmail dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.0.3 OS: FreeBSD / any
Private report: No CVE-ID: None
 [2004-12-20 18:19 UTC] mileskeaton at gmail dot com
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)


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-12-20 22:45 UTC] helly@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

In the first case the method is till abstract, hence the class must be abstract. In the other two cases we do not allow the superflous re-declaration of the abstract methods (maybe this is a feature request you want).

In general use \'ReflectionClass::export(\"YOURCLASSNAME\")\'
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 17 06:01:34 2024 UTC