Bug #80785 [Opn->Ver]: Complex inheritance depends on interface order
| From: | cmb@php.net | Date: | Mon, 11 Oct 2021 12:21:35 +0000 |
| Subject: | Bug #80785 [Opn->Ver]: Complex inheritance depends on interface order | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-237138@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=80785&edit=1
ID: 80785
Updated by: cmb@php.net
Reported by: peldax at gmail dot com
Summary: Complex inheritance depends on interface order
-Status: Open
+Status: Verified
Type: Bug
-Package: *General Issues
+Package: Scripting Engine problem
Operating System: All
PHP Version: 8.0.2
Block user comment: N
Private report: N
New Comment:
Confirmed: <https://3v4l.org/pLcNM>.
Previous Comments:
------------------------------------------------------------------------
[2021-02-22 22:45:00] 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-02-22 22:39:00] 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
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=80785&edit=1