Skip to content

Zend: Fix method inheritance depending on the order of the interfaces - #23638

Open
lazerg wants to merge 1 commit into
php:masterfrom
lazerg:fix/issue-23630-interface-inherit-order
Open

Zend: Fix method inheritance depending on the order of the interfaces#23638
lazerg wants to merge 1 commit into
php:masterfrom
lazerg:fix/issue-23630-interface-inherit-order

Conversation

@lazerg

@lazerg lazerg commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

interface C extends A, B {} fails while interface C extends B, A {} links, as soon as one parent carries a more specific signature than the other:

interface A { public function f(?string $name = null); }
interface B { public function f(?string $name = null, ?int $id = null); }

interface C extends A, B {} // Fatal error: Declaration of A::f() must be compatible with B::f()
interface D extends B, A {} // fine

When the child does not declare the method itself, the first parent's declaration is copied into its function table and every later parent is checked against that copy, so linking only works when the interface listed first happens to be the most specific one. Abstract classes are affected the same way.

The inherited method is now replaced when it is definitely not a valid override of a later parent while that parent is a valid override of it, which is the result the opposite order already produces. That is the approach nikic suggested in https://bugs.php.net/bug.php?id=76361. Only a definite error triggers it, so unresolved variance keeps the current behaviour, and signatures that genuinely conflict still fail in both orders.

Fixes #23630

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Override construct function with optional argument should not produce fatal error

1 participant