php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #80785 Complex inheritance depends on interface order
Submitted: 2021-02-22 22:39 UTC Modified: 2021-10-11 12:21 UTC
Votes:8
Avg. Score:4.1 ± 0.9
Reproduced:6 of 6 (100.0%)
Same Version:3 (50.0%)
Same OS:4 (66.7%)
From: peldax at gmail dot com Assigned:
Status: Verified Package: Scripting Engine problem
PHP Version: 8.0.2 OS: All
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 you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: peldax at gmail dot com
New email:
PHP Version: OS:

 

 [2021-02-22 22:39 UTC] peldax at gmail dot com
Description:
------------
Hello,

I have come across some special behaviour in inheritance. I am not sure how to clearly describe the bug, please come to see the example below.

Code below throws following error:

Fatal error: Declaration of ParentType::accept(ParentVisitor $visitor): mixed must be compatible with ChildType::accept(ChildVisitor $visitor): mixed in /in/sYmmm on line 9


BUT the code in the example works correctly when I switch the order of interfaces in extends for the "Final" interface.

interface Final extends ChildType, OtherInterface {}

Compiles successfully.


Test script:
---------------
<?php

interface ChildVisitor { /* some visiting methods */ }

interface ParentVisitor extends ChildVisitor { /* some extra visiting methods */ }

interface ParentType
{
    public function accept(ParentVisitor $visitor) : mixed;
}

interface ChildType extends ParentType
{
    public function accept(ChildVisitor $visitor) : mixed;
}

interface OtherInterface extends ParentType {}

interface Final extends OtherInterface, ChildType {}

Expected result:
----------------
Compile successfully.

Actual result:
--------------
Fatal error: Declaration of ParentType::accept(ParentVisitor $visitor): mixed must be compatible with ChildType::accept(ChildVisitor $visitor): mixed in /in/sYmmm on line 9

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-02-22 22:45 UTC] peldax at gmail dot com
Ofc the name of the Final interface cannot be "Final",

Here is the link for the live preview: https://3v4l.org/7u3Pn
 [2021-10-11 12:21 UTC] cmb@php.net
-Status: Open +Status: Verified -Package: *General Issues +Package: Scripting Engine problem
 [2021-10-11 12:21 UTC] cmb@php.net
Confirmed: <https://3v4l.org/pLcNM>.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 20:01:29 2024 UTC