Re: [RFC] [Under Discussion] Constants in traits

From: Date: Wed, 22 Jun 2022 18:12:14 +0000
Subject: Re: [RFC] [Under Discussion] Constants in traits
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-118061@lists.php.net to get a copy of this message
> 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

« previous php.internals (#118061) next »