Bug #80785 [Com]: Complex inheritance depends on interface order

From: Date: Mon, 22 Feb 2021 22:45:00 +0000
Subject: Bug #80785 [Com]: Complex inheritance depends on interface order
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-232329@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 Comment by: peldax at gmail dot com Reported by: peldax at gmail dot com Summary: Complex inheritance depends on interface order Status: Open Type: Bug Package: *General Issues Operating System: All PHP Version: 8.0.2 Block user comment: N Private report: N New Comment: Ofc the name of the Final interface cannot be "Final", Here is the link for the live preview: https://3v4l.org/7u3Pn Previous Comments: ------------------------------------------------------------------------ [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

« previous php.bugs (#232329) next »