[php-src] PR #23638: Zend: Fix method inheritance depending on the order of the interfaces
| From: | lazerg | Date: | Wed, 09 Sep 2026 23:12:54 +0000 |
| Subject: | [php-src] PR #23638: Zend: Fix method inheritance depending on the order of the interfaces | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-38410@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/23638
Author: lazerg
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:
```php
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