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

From: Date: Mon, 22 Feb 2021 22:39:00 +0000
Subject: Bug #80785 [NEW]: Complex inheritance depends on interface order
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-232328@lists.php.net to get a copy of this message
From: peldax at gmail dot com Operating system: All PHP version: 8.0.2 Package: *General Issues Bug Type: Bug Bug description:Complex inheritance depends on interface order 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 bug report at https://bugs.php.net/bug.php?id=80785&edit=1 -- Fix committed: https://bugs.php.net/fix.php?id=80785&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=80785&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=80785&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=80785&r=needscript Try newer version: https://bugs.php.net/fix.php?id=80785&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=80785&r=support Expected behavior: https://bugs.php.net/fix.php?id=80785&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=80785&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=80785&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=80785&r=globals PHP version support discontinued: https://bugs.php.net/fix.php?id=80785&r=phptooold Daylight Savings: https://bugs.php.net/fix.php?id=80785&r=dst IIS Stability: https://bugs.php.net/fix.php?id=80785&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=80785&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=80785&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=80785&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=80785&r=mysqlcfg

« previous php.bugs (#232328) next »