php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #47106 extending interfaces (and abstract classes) inflexible
Submitted: 2009-01-14 19:05 UTC Modified: 2009-01-17 18:19 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: rico dot moorman at gmail dot com Assigned:
Status: Not a bug Package: Feature/Change Request
PHP Version: 5.2.8 OS: Linux
Private report: No CVE-ID: None
 [2009-01-14 19:05 UTC] rico dot moorman at gmail dot com
Description:
------------
With interfaces we are given the possibility to extend them too. We may define additional methods. But while it's possible to add new methods it's not possible to change the method signatures.

Within the "normal" class hierarchy on the other hand it's possible though.

Adding this to the Interface implementation would surely lead to more overall flexibility of the Interfaces/abstracts.

Reproduce code:
---------------
// interfaces to test with
interface MillableInterface { }
interface StoneInterface extends MillableInterface { }
interface WheatInterface extends MillableInterface { }

// works actually
class Mill {
    function mill(MillableInterface $stuff) {}
}
class StoneMill extends Mill {
    function mill(StoneInterface $stuff) {}
}
class WheatMill extends Mill {
    function mill(WheatInterface $stuff) {}
}

// doesn't work
interface MillInterface {
    function mill(MillableInterface $stuff);
}
interface StoneMillInterface extends MillInterface {
    function mill(StoneInterface $stuff);
}
interface WheatMillInterface extends MillInterface {
    function mill(WheatInterface $stuff);
}

Expected result:
----------------
no fatals ... just a working interface check

Actual result:
--------------
Fatal error: Can't inherit abstract function MillInterface::mill() (previously declared abstract in StoneMillInterface) in /home/rico/dingen.php on line 29

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-01-17 18:19 UTC] johannes@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

The derived intrface must fullfill the "is-a" relationship, you can add optional paramters, but all calls which are allowed with the parent have to be allowed with the extended interface, too.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat May 18 09:01:33 2024 UTC