|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2021-02-22 22:45 UTC] peldax at gmail dot com
[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
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Nov 04 12:00:01 2025 UTC |
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