[php-src] Issue #24637: Child constructor is checked against only one interface constructor, depending on the order of implements

From: Date: Sat, 24 Oct 2026 09:49:15 +0000
Subject: [php-src] Issue #24637: Child constructor is checked against only one interface constructor, depending on the order of implements
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-253154@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/24637 Author: zeynallow ### Description When a class implements several interfaces that declare a constructor, a child class overriding the constructor is only checked against one of those interfaces. Which one depends on the order of the implements list, so an incompatible constructor may be accepted silently. ```php <?php interface A { public function __construct(int|float $p); } interface B { public function __construct(int $p); } class X implements A, B { public function __construct(int|float $p) {} } class Y extends X { public function __construct(int $p) {} } echo "no error\n"; ``` Resulted in this output: ``` no error ``` But I expected this output instead: ``` Fatal error: Declaration of Y::__construct(int $p) must be compatible with A::__construct(int|float $p) ``` With class X implements B, A instead, the expected fatal error is emitted. This is the known issue described in the XFAIL test Zend/tests/inheritance/interface_constructor_prototype_002.phpt. The cause seems to be that a constructor only has a single prototype, which ends up pointing at the last processed interface, and the child is only checked against that prototype. I have a working patch that additionally checks the child constructor against the constructors of all interfaces implemented by the parent (all of Zend/tests passes, and the XFAIL test passes). Since it turns code that currently compiles into a compile error, I would like to ask how to proceed before opening a PR: 1. Emit the fatal error directly (master only, with an UPGRADING note), or 2. Emit a deprecation for now and make it an error in a later version. Possibly related: #23630 / #23638 (method inheritance depending on interface order). ### PHP Version ```plain PHP 8.7.0-dev (cli) (NTS DEBUG), master at 4ae838f85e Zend Engine v4.7.0-dev, Copyright © Zend by Perforce with Zend OPcache v8.7.0-dev, Copyright ©, by Zend by Perforce Also reproduced on PHP 8.4.28-dev (cli) (NTS DEBUG), PHP-8.4 branch. ``` ### Operating System _No response_

« previous php.bugs (#253154) next »