php / php/php-src

Override construct function with optional argument should not produce fatal error

Open
#23,630 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Status: Needs Triage
Dominant language
C
Stars
40.4k
Forks
8.1k
Avg merge
2d 13h
Merged PRs (30d)
96

Description

Description

The following code:

<?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
    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
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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the two interface-inheritance snippets in PHP 8.4.24, comparing the parent-interface order and the resulting constructor compatibility error. Start by tracing the engine path that validates inherited interface methods; done means both declaration orders behave consistently without the reported fatal error, with a regression test covering the case.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.