On Thu, Mar 24, 2022 at 1:00 PM Rowan Tommins <rowan.coll...@gmail.com> wrote:
> On 23/03/2022 18:54, Mark Niebergall wrote: > > The next phase of work with different RFC would take > > this further with const inheritance, where const type must match. > > > I'm not sure it makes much sense to split this into two RFCs, and as far > as I can see, the previous RFC included both features: > > > Class constants are covariant. This means that the type of a class > constant is not allowed to be widen during inheritance. > > > Or is there something more you mean by "const inheritance", which isn't > covered by the RFC's examples? > Agreed, the more discussion that is going on, the more I'm leaning towards to see this implemented in a single RFC. The true value comes with the full feature set. Correct the original RFC discusses some inheritance, but didn't expand it out the way I'm thinking. It only details ensuring the concrete class has a matching type. I'm proposing additionally allowing blank values to be set by the concrete class. Existing draft RFC (https://wiki.php.net/rfc/typed_class_constants): ``` class Test { private const int A = 1; public const mixed B = 1; public const int C = 1; } class Test2 extends Test { // this is legal (because Test::A is private) public const string A = 'a'; // this is legal public const int B = 0; // this is illegal public const mixed C = 0; } ``` What I'm proposing would further allow const without values in abstracts and interfaces, which require concrete classes to have a value: ``` abstract class Test { private const int A = 1; public const mixed B = 1; public const int C = 1; // no value set, this is legal, concrete classes must set value public const int D; } interface TestInterface { // no value set, this is legal public const string NAME; } class Test2 extends Test implements TestInterface { // this is legal (because Test::A is private) public const string A = 'a'; // this is legal public const int B = 0; // these are required due to inheritance public const int D = 5; public const string NAME = 'EmperorPenguin'; // this is illegal public const mixed C = 0; } ``` > > > Regards, > > -- > Rowan Tommins > [IMSoP] > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php > >