php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #35832 interface from extended class conflicts with interface of parent class
Submitted: 2005-12-28 22:14 UTC Modified: 2005-12-28 22:48 UTC
From: sp0n9e at gmail dot com Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5.1.1 OS: Windows XP
Private report: No CVE-ID: None
 [2005-12-28 22:14 UTC] sp0n9e at gmail dot com
Description:
------------
when implementing interfaces that have common methods in a parent class and an extended class, the code below produces an error.  if i provide a method in the child class, it works.  it also works if the parent class doesn't implement its' interface.  but i think i should be able to inherit from the parent class and satisfy both interfaces.  though it would be easy in this example to "code around" the problem, i ran across this in a situation where it won't be quite as easy.

Reproduce code:
---------------
<?php
interface gotsMyMethod {
	public function myMethod();
}
class theparent implements gotsMyMethod {
	public function myMethod() {
		return "boo!";
	}
}
interface iNeedsMyMethod {
	public function myMethod();
}
class child extends theparent implements iNeedsMyMethod {
}
$child = new child();
echo $child->myMethod();
?>

Expected result:
----------------
I expect the code to run without any errors and output "boo!"

Actual result:
--------------
Fatal error: Can't inherit abstract function iNeedsMyMethod::myMethod() (previously declared abstract in gotsMyMethod) in C:\www\test\bug.php on line 13

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-12-28 22:39 UTC] sniper@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5.1-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5.1-win32-latest.zip


 [2005-12-28 22:48 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

function myMethod() is abstract in two different interfaces and a class can only implement the function once, hence the error.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 20 05:01:27 2024 UTC