Re: [PHP-DEV] [RFC] [Under Discussion] Constants in traits

This is only part of a thread. view whole thread
June 22, 2022 18:12 (Claude Pache)
> Le 21 juin 2022 à 23:33, shinji igarashi <> a écrit : > > Hello everyone! > > I'd like to start a discussion on an RFC to allow defining constants in traits. > > > I'm looking forward to your feedback, including corrections on English wordings. > > Thanks! > > -- > Shinji Igarashi >
Hi, Some time ago, I migrated part of some class implementation into a trait, and I was surprised that it resulted in a syntax error, because constants were not supported in traits. In my case, I could trivially resolve the issue by morphing the (private) constant into a static property (semantically less correct, but pragmatically simpler); but I was feeling that it is yet one more inconsistency of PHP: Why on earth are static properties supported, but not constants? So, this is a welcome addition (or, rather, a welcome correction of an oversight). —Claude