[php-src] Issue #9272: 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

From: Date: Mon, 08 Aug 2022 14:25:58 +0000
Subject: [php-src] Issue #9272: 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
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-242151@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/9272 Author: MaXal ### Description The following code: ```php <?php trait T { public const a = C2::b; } class C1 { use T; const b = 1; } class C2 extends C1 { use T; const b = 2; } echo C1::a; echo C2::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; ``` and outputs ``` 11 ``` ### PHP Version 8.2 ### Operating System _No response_

« previous php.bugs (#242151) next »