Re: [PHP-DEV] Trait constants

2021-05-19 Thread Guilliam Xavier
On Wed, May 12, 2021 at 12:22 PM Stephen Reay 
wrote:

>
> Any thoughts on
> https://github.com/stephenreay/php-rfcs/blob/master/trait-constants.md ?
>

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


Re: [PHP-DEV] Trait constants

2021-05-12 Thread Stephen Reay


> On 12 May 2021, at 16:44, Nikita Popov  wrote:
> 
> On Wed, May 12, 2021 at 11:38 AM Guilliam Xavier  >
> wrote:
> 
>> 
>> 
>> On Sun, Jun 28, 2020 at 2:34 PM Nikita Popov  wrote:
>> 
>>> On Sat, Jun 27, 2020 at 3:53 PM Stephen Reay 
>>> 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

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 
 ?



Cheers

Stephen 

Re: [PHP-DEV] Trait constants

2021-05-12 Thread Nikita Popov
On Wed, May 12, 2021 at 11:38 AM Guilliam Xavier 
wrote:

>
>
> On Sun, Jun 28, 2020 at 2:34 PM Nikita Popov  wrote:
>
>> On Sat, Jun 27, 2020 at 3:53 PM Stephen Reay 
>> 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


Re: [PHP-DEV] Trait constants

2021-05-12 Thread Guilliam Xavier
On Sun, Jun 28, 2020 at 2:34 PM Nikita Popov  wrote:

> On Sat, Jun 27, 2020 at 3:53 PM Stephen Reay 
> 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


Re: [PHP-DEV] Trait constants

2020-07-07 Thread Stephen Reay

> On 28 Jun 2020, at 19:33, Nikita Popov  wrote:
> 
> On Sat, Jun 27, 2020 at 3:53 PM Stephen Reay  >
> 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 



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 

Re: [PHP-DEV] Trait constants

2020-06-28 Thread Nikita Popov
On Sat, Jun 27, 2020 at 3:53 PM Stephen Reay 
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


Re: [PHP-DEV] Trait constants

2020-06-27 Thread tyson andre
> 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? 

I don't think there's any insurmountable obstacles, but it would be useful to 
add a lot of tests because of potential edge cases (resolution, opcache, 
reference counting)
involved in traits and adding new places where constants can go.

(I'd also worked on a declined RFC and implementation for changing what could 
be used in a constant expression)

```
getMessage() . "\n";
}
D::main();
/*
Output:

from c
Undefined class constant 'self::OTHER_CONST'
>From D
 */
```

- Tyson
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php



Re: [PHP-DEV] Trait constants

2020-06-27 Thread tyson andre
> 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? 

I'm in favor of adding it. I doubt there's any insurmountable technical 
obstacles.
(I work on a static analyzer for php (https://github.com/phan/phan) and don't 
expect technical issues with that proposal)
I personally find it inconvenient to put constants used by traits in different 
classes/interfaces or in properties.

Other languages allow adding constants to traits:

- Java allows defining constants on interfaces, which allow defining default 
method implementations like PHP traits
- 
https://doc.rust-lang.org/edition-guide/rust-2018/trait-system/associated-constants.html
 allows defining constants with values on traits
  (it also does various other things that impractical for php)

One thing to document/add tests for would be the resolution of `self::MY_CONST`.
In a trait, `self::method()` may be overridden by the method of the class 
that's using the trait.
I'd expect `self::MY_CONST` to be the same.

```php
https://www.php.net/manual/en/language.oop5.traits.php#language.oop5.traits.conflict
  (e.g. `use A, B { const A::MY_CONST insteadof B; }`)
- We already check if there are conflicting values when inheriting constants 
from an interface and another interface/trait.

Cheers,
- Tyson
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php



Re: [PHP-DEV] Trait constants

2020-06-27 Thread Mike Schinkel
> On Jun 27, 2020, at 9:52 AM, Stephen Reay  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? 


Yes.  Please.


-Mike

[PHP-DEV] Trait constants

2020-06-27 Thread Stephen Reay
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? 


Cheers 



Stephen  
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php