|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #71825 PHP does not allow weaker parameter signature in child interface/class.
Submitted: 2016-03-14 22:32 UTC Modified: 2017-01-29 07:34 UTC
Avg. Score:4.0 ± 1.1
Reproduced:5 of 5 (100.0%)
Same Version:3 (60.0%)
Same OS:4 (80.0%)
From: andreas at dqxtech dot net Assigned:
Status: Suspended Package: Class/Object related
PHP Version: 7.0.4 OS: Linux
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.
Block user comment
Status: Assign to:
Bug Type:
From: andreas at dqxtech dot net
New email:
PHP Version: OS:


 [2016-03-14 22:32 UTC] andreas at dqxtech dot net
The Liskov substitution principle requires that any child thingy can replace the parent thingy. It does not require the opposite.

A weaker signature should be ok with the LSP.
Unfortunately, in PHP, it is not.


See also
"if the parameters are contravariant then the types are respected. If PHP was pure OO then there would be no problem, since Array would be narrower than Object (assuming that no type in the declaration means any object)."

One can always dream..

And, just saying: Others are making arguments about overloading. I think this is really a different story and does not apply here. To overload, you will use a narrower signature, so that the version of the method is only applied in some cases, not all. On the other hand, the broader / weaker signature always includes all cases of the parent, so this version will always be used.

Test script:
interface I {
    function foo(J $j);

interface J extends I {
    function foo(I $i);

Expected result:
Compile just fine.

Actual result:
"Fatal error: Declaration of J::foo() must be compatible with that of I::foo()"


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2016-03-14 22:54 UTC] andreas at dqxtech dot net
 [2016-03-26 21:31 UTC]
-Status: Open +Status: Closed -Assigned To: +Assigned To: krakjoe
 [2016-03-26 21:31 UTC]
For this kind of change, an RFC is required.

Please see:
 [2016-03-26 21:42 UTC]
-Status: Closed +Status: Suspended
 [2016-04-04 14:32 UTC]
Yes, Liskov "widening" has been so many times debated so far, with no consensus about it.
We'll need to reopen the discussion through a RFC for it
 [2017-01-29 07:34 UTC]
-Assigned To: krakjoe +Assigned To:
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Jul 21 19:01:34 2024 UTC