php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #34808 Interface is forced on child classes even though parent class has implemented.
Submitted: 2005-10-10 12:29 UTC Modified: 2005-10-10 12:32 UTC
From: daarius at hotmail dot com Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5.0.5 OS: WinXP
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: daarius at hotmail dot com
New email:
PHP Version: OS:

 

 [2005-10-10 12:29 UTC] daarius at hotmail dot com
Description:
------------
The interface of a parent class is also forced to be implemented on to the children classes if they use methods with same name as in Interface. Even though the parent class has implemented the methods declared in the Interface legally.

Reproduce code:
---------------
interface MyInterface {
   public function Z($s);
}

class MyClass implements MyInterface {
   public function Z($s) {}
}

class MySubClass extends MyClass {
   public function Z() {}
}


Expected result:
----------------
Above should be legal (at least i think), because parent is implementing the interface, the child is just extending the parent's method.

But, if we remove the method completely from child class, then there is no error message and Interface is no longer being forced on to child. This suggests inconsistency.

Also, if we remove the interface from the code, then the parent child extension of the same method name is still legal, as the number of arguments is not being checked anymore.

Actual result:
--------------
Fatal error: Declaration of MySubClass::Z() must be compatible with that of MyInterface::Z() in C:\httpd\PHPObject3.0\index.php on line 12

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-10-10 12:32 UTC] sniper@php.net
Please do not submit the same bug more than once. An existing
bug report already describes this very problem. Even if you feel
that your issue is somewhat different, the resolution is likely
to be the same. 

Thank you for your interest in PHP.

See bug #34807

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 07:01:29 2024 UTC