Skip to content

Collision of interface constant and trait constant doesn't produce fatal error #9271

Open
@MaXal

Description

@MaXal

Description

The following code:

<?php

trait MyTrait{
    const A = 1;
}
interface I{
    const A = 2;
}

class D implements I{
    use MyTrait;
}

echo D::A;

Resulted in this output:

1

But I expected this output instead:

Fatal error: I and MyTrait define the same constant (A) in the composition of D. However, the definition differs and is considered incompatible. Class was composed in /in/EVuKh on line 10

PHP Version

8.2

Operating System

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions