php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #34807 Interface is forced on child classes even though parent class has implemented.
Submitted: 2005-10-10 12:27 UTC Modified: 2005-10-10 20:20 UTC
From: daarius at hotmail dot com Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5.* OS: *
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: daarius at hotmail dot com
New email:
PHP Version: OS:

 

 [2005-10-10 12:27 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 try using this CVS snapshot:

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


 [2005-10-10 16:01 UTC] daarius at hotmail dot com
I have tried the latest snapshot. The error is some on there too.
 [2005-10-10 20:20 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

You cannot redeclare methods in PHP. Reread the error message.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 12:01:27 2024 UTC