You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fatal error: class and trait define the same constant in the composition of child class in case constant in trait is equal to constant in child class #9272
<?phptrait T {
publicconsta = C2::b;
}
classC1 {
use T;
constb = 1;
}
classC2extendsC1 {
use T;
constb = 2;
}
echoC1::a;
echoC2::a;
Resulted in this output:
Fatal error: C1 and T define the same constant (a) in the composition of C2. However, the definition differs and is considered incompatible. Class was composed in /in/riAnX on line 9
But I expected this output instead:
22
It's not clear to me why this code is incorrect, but at the same time, the following works:
<?php
trait T {
public const a = self::b;
}
class C1 {
use T;
const b = 1;
}
class C2 extends C1 {
use T;
const b = 2;
}
echo C1::a;
echo C2::a;