Re: Trait constants

From: Date: Tue, 07 Jul 2020 16:25:26 +0000
Subject: Re: Trait constants
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-110865@lists.php.net to get a copy of this message
> On 28 Jun 2020, at 19:33, Nikita Popov <nikita.ppv@gmail.com> wrote: > > On Sat, Jun 27, 2020 at 3:53 PM Stephen Reay <php-lists@koalephant.com > <mailto:php-lists@koalephant.com>> > wrote: > >> Hi, >> >> It’s always struck me as slightly odd that traits don’t support constants >> the way classes and interfaces do. >> I tried to find an explanation of the lack of support in the original RFC, >> and came up empty. >> >> A consequent discussion in R11 has led me here. >> Can anyone working on internals explain why traits don’t allow constants >> (either technically or philosophically)? >> Moreover, what’s the opinion(s) of the list, on adding support for this? >> Would an RFC be needed? >> > > Sounds like a reasonable addition. An RFC will be needed to specify the > details, which tend to be tricky whenever traits are involved. Some > suggestions: > > * Constants mustn't be accessible directly on the trait, i.e. > TraitName::FOOBAR throws. self::FOOBAR within the trait is legal in that > "self" is remapped to the using class, as usual. > * The same constants important from multiple traits should follow the > rules of properties, i.e. require that values match. Conflict resolution > for constants should very much *not* be supported. > > Regards, > Nikita Hi All, I finally found some time to write something to get this started. I’m following the advice given, and putting this on GH initially, any and all comments/feedback/suggestions are welcome! https://github.com/stephenreay/php-rfcs/blob/master/trait-constants.md <https://github.com/stephenreay/php-rfcs/blob/master/trait-constants.md> Note: I realise it doesn’t lay out voting choices, target version etc: It seems more pertinent to focus on nailing down some kind of fixed target of what should be achieved, before detailing the when/etc. Cheers Stephen

« previous php.internals (#110865) next »