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

This is only part of a thread. view whole thread
  118061
June 22, 2022 18:12 claude.pache@gmail.com (Claude Pache)
> Le 21 juin 2022 à 23:33, shinji igarashi <sji@sj-i.dev> a écrit : > > Hello everyone! > > I'd like to start a discussion on an RFC to allow defining constants in traits. > https://wiki.php.net/rfc/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