php / php-src

The PHP Interpreter
https://www.php.net
Other
38.16k stars 7.75k forks source link

Enums should not be allowed to implement interfaces with properties in 8.4 #16447

Open vudaltsov opened 2 weeks ago

vudaltsov commented 2 weeks ago

Description

The following code:

interface I
{
    public string $x { get; }
}

enum E implements I
{
}

Resulted in this output:

PHP Fatal error:  Enum E must implement 1 abstract private method (I::$x::get)

But I expected this output instead:

PHP Fatal error:  Enum E cannot implement interfaces with properties

PHP Version

PHP 8.4.0-dev (cli) (built: Sep 24 2024 14:38:59) (NTS)

Operating System

MacOS

vudaltsov commented 2 weeks ago

By the way, why I::$x::get is called "private" in the error?

DanielEScherzer commented 2 weeks ago

"private" was fixed in master but not 8.4, see #15995 I'll work on a patch for better enum error messages