On 04/01/2022 22:35, Kirill Nesmeyanov wrote:
Since «traits» are often an indicator of not very good code and many may not 
use them quite correctly, for example, as helpers, I suggest adding support for 
the `expects` keyword to indicate that the trait is part of the code 
decomposition taking into account ISP.


Hi Kirill,

I'm a little confused what problem this is trying to solve - in what way does using a trait in the "wrong" inheritance hierarchy constitute "abuse"?


On 04/01/2022 23:10, Bruce Weirdan wrote:
Prior art: @psalm-require-extends and @psalm-require-implements Psalm
annotations:https://psalm.dev/docs/annotating_code/supported_annotations/#psalm-require-extends

... and on 05/01/2022 12:36, Saif Eddin Gmati wrote:
ref:https://docs.hhvm.com/hack/traits-and-interfaces/trait-and-interface-requirements


The examples in both of these cases appear to be using the requirements primarily as short-hand for listing abstract methods in the trait.

For instance:

interface FooInterface {
     public function doFoo();
}
trait SillyFooTrait {
    require implements FooInterface;
    public function doFooTwice() {
        $this->doFoo();
        $this->doFoo();
   }
}

Is essentially equivalent to:

trait SillyFooTrait {
    abstract public function doFoo();
    public function doFooTwice() {
        $this->doFoo();
        $this->doFoo();
   }
}


In other words, the requirement is there because it is actually a requirement for the trait to work correctly, not because of some perceived "correct" use of the trait. This doesn't seem to match your reasoning for proposing the syntax, so maybe I'm missing something?


Regards,

--
Rowan Tommins
[IMSoP]

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

Reply via email to