[php-src] Issue #23630: Override construct function with optional argument should not produce fatal error
| From: | Renji-FR | Date: | Wed, 09 Sep 2026 15:58:44 +0000 |
| Subject: | [php-src] Issue #23630: Override construct function with optional argument should not produce fatal error | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-252720@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/23630
Author: Renji-FR
### Description
The following code:
```php
<?php
interface MyInterface1 { public function __construct(?string $name = null); }
interface MyInterface2 { public function __construct(?string $name = null, ?int $id = null); }
interface MyInterface3 extends MyInterface1, MyInterface2 { }
```
Resulted in this output:
```
PHP Fatal error: Declaration of MyInterface1::__construct(?string $name = null) must be compatible
with MyInterface2::__construct(?string $name = null, ?int $id = null) in php shell code on line 1
```
But I expected no error and the following code works as expected:
```php
<?php
interface MyInterface1 { public function __construct(?string $name = null); }
interface MyInterface2 { public function __construct(?string $name = null, ?int $id = null); }
interface MyInterface4 extends MyInterface2, MyInterface1 { }
```
### PHP Version
```plain
PHP 8.4.24 (cli) (built: Jul 30 2026 15:23:13) (NTS)
Copyright (c) The PHP Group
Built by Ubuntu
Zend Engine v4.4.24, Copyright (c) Zend Technologies
with Zend OPcache v8.4.24, Copyright (c), by Zend Technologies
```
### Operating System
Ubuntu 24.04.4 LTS