Re: [PHP-DEV] Trait constants

This is only part of a thread. view whole thread
  114431
May 12, 2021 09:38 guilliam.xavier@gmail.com (Guilliam Xavier)
On Sun, Jun 28, 2020 at 2:34 PM Nikita Popov ppv@gmail.com> wrote:

> On Sat, Jun 27, 2020 at 3:53 PM Stephen Reay <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. >
Sorry for asking so late, but: why? Note that currently both TraitName::$foobar and TraitName::foobar() work: https://3v4l.org/eGlYm Thanks, -- Guilliam Xavier
  114434
May 12, 2021 09:44 nikita.ppv@gmail.com (Nikita Popov)
On Wed, May 12, 2021 at 11:38 AM Guilliam Xavier xavier@gmail.com>
wrote:

> > > On Sun, Jun 28, 2020 at 2:34 PM Nikita Popov ppv@gmail.com> wrote: > >> On Sat, Jun 27, 2020 at 3:53 PM Stephen Reay <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. >> > > Sorry for asking so late, but: why? > Note that currently both TraitName::$foobar and TraitName::foobar() work: > https://3v4l.org/eGlYm >
Yes, unfortunately this currently works by accident, but support for it will be removed ( https://wiki.php.net/rfc/deprecations_php_8_1#accessing_static_members_on_traits ). Regards, Nikita
  114438
May 12, 2021 10:22 php-lists@koalephant.com (Stephen Reay)
> On 12 May 2021, at 16:44, Nikita Popov ppv@gmail.com> wrote: > > On Wed, May 12, 2021 at 11:38 AM Guilliam Xavier xavier@gmail.com <mailto:guilliam.xavier@gmail.com>> > wrote: > >> >> >> On Sun, Jun 28, 2020 at 2:34 PM Nikita Popov ppv@gmail.com> wrote: >> >>> On Sat, Jun 27, 2020 at 3:53 PM Stephen Reay <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. >>> >> >> Sorry for asking so late, but: why? >> Note that currently both TraitName::$foobar and TraitName::foobar() work: >> https://3v4l.org/eGlYm >> > > Yes, unfortunately this currently works by accident, but support for it > will be removed ( > https://wiki.php.net/rfc/deprecations_php_8_1#accessing_static_members_on_traits <https://wiki.php.net/rfc/deprecations_php_8_1#accessing_static_members_on_traits> > ). > > Regards, > Nikita
Hi Nikita - thanks for your earlier input on this. As we’re heading towards 8.1 now seems as good a time as any to pick this back up. Any thoughts on https://github.com/stephenreay/php-rfcs/blob/master/trait-constants.md <https://github.com/stephenreay/php-rfcs/blob/master/trait-constants.md> ? Cheers Stephen
  114524
May 19, 2021 10:20 guilliam.xavier@gmail.com (Guilliam Xavier)
On Wed, May 12, 2021 at 12:22 PM Stephen Reay <php-lists@koalephant.com>
wrote:


Hi Stephen,

I agree with what has already been said, i.e.: that's a desirable feature,
but probably needs a proper RFC for more discussion.

Regards,

-- 
Guilliam Xavier